How to Use Arithmetic Assignment Operator in Java


In this example, let us learn how to use Arithmetic operators like + (addition), – (subtraction), * (multiplication) and / (division) in Java.

Source Code

package com.beginner.examples;

public class ArithmeticAssignmentOperatorExample {

	
	public static void main(String[] args) {
	
		int x=1;
		//x+=5 and x=x+5 are the same thing here
		x+=5;
		System.out.println("x="+x);
		
		//X goes up by 1
		x++;
		System.out.println("x="+x);
		
	}

}

Output:

x=6
x=7
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments