Equal To And Not Equal To Operator Example Java Program

Definition

Operators in Java are similar to those in C++. However, there is no delete operator due to garbage collection mechanisms in Java, and there are no operations on pointers since Java does not support them. Equal to operator assigns values to variables and also checks if two values are equal or not.

Syntax

variable_name = number;

Equal To And Not Equal To Operator Example Program

import java.util.Scanner;

class EqualToAndNotEqualToOperator{
	public static void main(String[] args){
		Scanner in=new Scanner(System.in);
		System.out.println("Enter any two numbers to check for equality: ");
		int num1=in.nextInt();
		int num2=in.nextInt();
		if(num1==num2){
		System.out.println("The two numbers are equal");
		}
		else if(num1!=num2){
		System.out.println("The numbers are not equal");
		}
	}
}

Sample Output

Output is
Enter any two numbers to check for equality:
67
67
The two numbers are equal


Enter any two numbers to check for equality:
34
30
The numbers are not equal