Write a Java program to compare two numbers
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..
import java.util.Scanner; public class Javaexcercise { public static void main( String args[] ) { Scanner input = new Scanner(System.in); int num1; int num2; System.out.print( "Input first integer: " ); num1 = input.nextInt(); System.out.print( "Input second integer: " ); num2 = input.nextInt(); if ( num1 == num2 ) System.out.printf( "%d == %d\n", num1, num2 ); if ( num1 != num2 ) System.out.printf( "%d != %d\n", num1, num2 ); if ( num1 < num2 ) System.out.printf( "%d < %d\n", num1, num2 ); if ( num1 > num2 ) System.out.printf( "%d > %d\n", num1, num2 ); if ( num1 <= num2 ) System.out.printf( "%d <= %d\n", num1, num2 ); if ( num1 >= num2 ) System.out.printf( "%d >= %d\n", num1, num2 ); } }
Result:
Input first integer: 50
Input second integer: 50
50 == 50
50 <= 50
50 >= 50
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.
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..
Result:
Input first integer: 50
Input second integer: 50
50 == 50
50 <= 50
50 >= 50
need an explanation for this answer? contact us directly to get an explanation for this answer