Java program to check the number is equal to 2000 or not

 Java program to check the number is equal to 2000 or not

1. Java program to check the number is equal to 2000 or not using if- else statement:

Program:

import java.io.*;
import java.util.*;
class EqualsTo
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number");
int num= sc.nextInt();
if(num==2000)
{
System.out.println("Number equals to 2000");
}
else
{
System.out.println("Number not equals to 2000");
}
}
}

output:

Enter the number
2001
Number not equals to 2000

2. Java program to check the number is equal to 2000 or not using Buffered Reader class:

Program:

import java.util.*;
import java.lang.*;
import java.io.*;
class EqualTo
{
public static void main(String args[]) throws Exception
{

BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the value");
int v= Integer.parseInt(br.readLine());
if(v== 2000)
{
System.out.println("Number are equal");
}
else
{
System.out.println("Number are not equal");
}
}
}

Output:

Enter the value
2001
Number are not equal

3. Java program to check the number is equal to 2000 or not using Constructor:

Program:

import java.util.*;
class CrArea
{
	
	CrArea(int n1)
	{
	 if(n1== 2000)
	 {
		 System.out.println("Numbers are equal");
	 }
	 else
	 {
		 System.out.println("Numbers are not equal");
	 }
	}
}
class CrArea1
{
   public static void main(String args[]) 
    {   
      Scanner sc= new Scanner(System.in);
      System.out.println("Enter the value of number1");
      int num1= sc.nextInt();   
      CrArea obj= new CrArea(num1);
	      
   }
 }

Output:

Enter the value of number1
2000
Numbers are equal
Enter the value of number1
2001
Numbers are not equal

4. Java program to check the number is equal to 2000 or not using Command Line Argument:

Program:

import java.util.*;
class GreatestOfTwo
{
public static void main(String args[])
{
 
int num1= Integer.parseInt(args[0]);
System.out.println(num1);

if(num1==2000)
{
	System.out.println("Numbers are equal");
}
else
{
	System.out.println("Numbers are not equal");
}
}
}

Compile:

javac GreatestOfTwo.java

Run:

java GreatestOfTwo 2000
2000
Numbers are equal

Leave a Comment