Java Program to Check if Two Numbers are Equal

This is a Java Program to Accept two Integers and Check if they are Equal.

Enter two integer numbers as input. After that we match both the inputs with the help of equal to(==) operator. Hence we generate the output accordingly.

Here is the source code of the Java Program to Accept two Integers and Check if they are Equal. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.

  1. import java.util.Scanner;
  2. public class Equal_Integer 
  3. {
  4.     public static void main(String[] args) 
  5.     {
  6.         int m, n;
  7.         Scanner s = new Scanner(;
  8.         System.out.print("Enter the first number:");
  9.         m = s.nextInt();
  10.         System.out.print("Enter the second number:");
  11.         n = s.nextInt();
  12.         if(m == n)
  13.         {
  14.             System.out.println(m+" and "+n+" are equal ");
  15.         }
  16.         else
  17.         {
  18.             System.out.println(m+" and "+n+" are not equal ");
  19.         }
  20.     }
  21. }


$ javac
$ java Equal_Integer
Enter the first number:5
Enter the second number:7
5 and 7 are not equal
Enter the first number:6
Enter the second number:6
6 and 6 are equal

Sanfoundry Global Education & Learning Series – 1000 Java Programs.

Note: Join free Sanfoundry classes at Telegram or Youtube

Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & technical discussions at Telegram SanfoundryClasses.