Computer Science, asked by yashassudesh, 5 months ago

write a java program to input two numbers and check whether the 1st number is
greater than 2nd number or the 1st number is smaller than 2nd
number or both the numbers are equal

Answers

Answered by mjeystech
1

Answer:

Java Code:

  1. import java.util.Scanner;
  2. public class Exercise32 {
  3. public static void main( String args[] )
  4. {
  5. // create Scanner to obtain input from command window
  6. Scanner input = new Scanner(System.in);
  7. int number1; // first number to compare
  8. int number2; // second number to compare
  9. System.out.print( "Input first integer: " ); // prompt
  10. number1 = input.nextInt(); // read first number from user
  11. System.out.print( "Input second integer: " ); // prompt
  12. number2 = input.nextInt(); // read second number from user
  13. if ( number1 == number2 )
  14. System.out.printf( "%d == %d\n", number1, number2 );
  15. if ( number1 != number2 )
  16. System.out.printf( "%d != %d\n", number1, number2 );
  17. if ( number1 < number2 )
  18. System.out.printf( "%d < %d\n", number1, number2 );
  19. if ( number1 > number2 )
  20. System.out.printf( "%d > %d\n", number1, number2 );
  21. if ( number1 <= number2 )
  22. System.out.printf( "%d <= %d\n", number1, number2 );
  23. if ( number1 >= number2 )
  24. System.out.printf( "%d >= %d\n", number1, number2 );
  25. }
  26. }

Similar questions