Check Two Numbers For Equality in Java

Check number is same or not in java. 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. 

import java.util.Scanner;
public class Main
public static void main(String[] args)
int m, n;
Scanner s = new Scanner(;
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 in Java

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

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.