Write a Java program to compare two numbers


Introduction

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. import java.util.Scanner;
  2. public class Javaexcercise {
  3. public static void main( String args[] )
  4. {
  5.  
  6. Scanner input = new Scanner(System.in);
  7. int num1;
  8. int num2;
  9.  
  10. System.out.print( "Input first integer: " );
  11. num1 = input.nextInt();
  12.  
  13. System.out.print( "Input second integer: " );
  14. num2 = input.nextInt();
  15.  
  16. if ( num1 == num2 )
  17. System.out.printf( "%d == %d\n", num1, num2 );
  18. if ( num1 != num2 )
  19. System.out.printf( "%d != %d\n", num1, num2 );
  20. if ( num1 < num2 )
  21. System.out.printf( "%d < %d\n", num1, num2 );
  22. if ( num1 > num2 )
  23. System.out.printf( "%d > %d\n", num1, num2 );
  24. if ( num1 <= num2 )
  25. System.out.printf( "%d <= %d\n", num1, num2 );
  26. if ( num1 >= num2 )
  27. System.out.printf( "%d >= %d\n", num1, num2 );
  28. }
  29. }

Result

java techstudy.org

     





Related Topics




Popular Posts