Write a java program to accept two numbers and check which is same or not. This is a Java program that accepts two integers and compares them to see if they’re equal. As input, enter two integer numbers. After that, we use the equal to operator to match both inputs. As a result, the output is generated appropriately. The Java Program to accept Two Integers and check if they Are equal can be found here.
public class Main
public static void main(String args)
int m, n;
Scanner s = new Scanner(System.in);
System.out.print("Enter the first number");
m = s.nextInt();
System.out.print("Enter the second number");
n = s.nextInt();
if(m == n)
System.out.println(m+" and "+n+" are same");
System.out.println(m+" and "+n+" are not same");
Enter the first number34
Enter the second number43
34 and 43 are not same
If else statement in java program
For a single condition, the if-else statement is used to conduct two operations. The if-else statement is an expansion of the if statement that allows us to conduct two different operations, one for the condition’s correctness and the other for its incorrectness. It is important to note that the if and else blocks cannot be executed concurrently.
Scanner in java program
Scanner is a class in the Java util package that is used to get input of primitive kinds such as int, double, and strings.
It’s the simplest way to read input in a Java program, but it’s not very efficient if you’re looking for an input method for situations where time is a factor, such as competitive programming.