Thursday, February 29, 2024

Java program to check greater number between two numbers using conditional operator.

import java.util.Scanner;

public class GreaterNumberChecker {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter the first number: ");
        int number1 = scanner.nextInt();

        System.out.print("Enter the second number: ");
        int number2 = scanner.nextInt();

        int greaterNumber = (number1 > number2) ? number1 : number2;

        System.out.println("The greater number is: " + greaterNumber);
    }
}

No comments:

Post a Comment

Java program to implement file input stream class to read binary data from image file.

import java.io.FileInputStream; import java.io.IOException; public class ReadImageFile {     public static void main(String[] args) {       ...