Addition And Assignment Operator Example Java Program

Definition

Operators are constructs which behave generally like functions, but which differ syntactically or semantically from usual functions. Common simple examples include arithmetic (addition with +, comparison with >) and logical operations (such as AND or &&). More involved examples include assignment (usually = or :=), field access in a record or object (usually .), and the scope resolution operator (often ::). Addition and assignment operator means "find the number stored in the variable x, add 1 to it, and store the result of the addition in the variable x."

Syntax

variable_name1+=variable_name2;

Addition And Assignment Operator Example Program

class AdditionAndAssignmentOperator{
	public static void main(String[] args){
		int num1,num2,num3;
		num1=7;
		num2=8;
		num3=11;
		System.out.println("num1=7; num2=8; num3=11");
		num1+=num2;
		num1+=num3;
		System.out.println("The result after addition of these three numbers is : "+num1);
	}
}

Sample Output

Output is:
num1=7; num2=8; num3=11
The result after addition of these three numbers is : 26