Assignment 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. Assignment operator assigns a value to a particular variable.

Syntax

Variable_name = Variable_name;

Assignment Operator Example Program

import java.util.Scanner;
class AssignmentOperator{
	public static void main(String[] args){
		Scanner in=new Scanner(System.in);
		System.out.print("Enter num1: ");
		int num1=in.nextInt();
		System.out.println("The value "+num1+" is assigned to the variable num1");
		System.out.print("Enter num2: ");
		int num2=in.nextInt();
		System.out.println("The value "+num2+" is assigned to the variable num2");
	}
}

Sample Output

Output is
Enter num1: 34
The value 34 is assigned to the variable num1
Enter num2: 23
The value 23 is assigned to the variable num2