Write a Java program to compare two numbersInput Data:Input first integer: 25Input second integer: 39
Expected Output
25 != 39 25 < 39 25 <= 39
import java.util.Scanner; public class Exercise32 { public static void main( String args[] ) { // create Scanner to obtain input from command window Scanner input = new Scanner(System.in); int number1; // first number to compare int number2; // second number to compare System.out.print( "Input first integer: " ); // prompt number1 = input.nextInt(); // read first number from user System.out.print( "Input second integer: " ); // prompt number2 = input.nextInt(); // read second number from user if ( number1 == number2 ) System.out.printf( "%d == %d\n", number1, number2 ); if ( number1 != number2 ) System.out.printf( "%d != %d\n", number1, number2 ); if ( number1 < number2 ) System.out.printf( "%d < %d\n", number1, number2 ); if ( number1 > number2 ) System.out.printf( "%d > %d\n", number1, number2 ); if ( number1 <= number2 ) System.out.printf( "%d <= %d\n", number1, number2 ); if ( number1 >= number2 ) System.out.printf( "%d >= %d\n", number1, number2 ); } }
Sample Output:
Input first integer: 25 Input second integer: 39 25 != 39 25 < 39 25 <= 39
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer