Operators in Java(Part3)

Damitha karunarathne
2 min readMay 12, 2020


Hi readers You are with my Sixth article Of Java.Thank you very much for being with me so far and I thoroughly believe that you have read my previous articles and go through with my simple examples.I am pretty sure that they are very useful.This article is third part of java operators.Mainly here I discuss about Assignment Operators in java.

Assignment operators in java

Assignment operator (=), which assigns a value to a variable.

x+=y means x=x+y

x-=y means x=x-y

x*=y means x=x*y

x/=y means x=x/y

x%=y means x=x%y

With in some examples it may easy to understand more about Assignment Operators in Java.


int num1=5;
int num2=2;
num2*=num1+num2; //num2=num2(num1+num2)
System.out.println(num2); // num2=2(5+2)=14


int var1 = 7;
int var2 = 3;
int var3 = var2;
int var4 = var2;
int var7 = var2;
int var5 = var1%(++var2); //(++var2)=4,7%4=3
System.out.println(var1%(++var3));//(++var3)=4, 7%4=3 System.out.println(var1%++var7); // (++var7)=4, 7%4=3 System.out.println(var1%var4++);// (var4++)=3, 7%3=1 System.out.println(var4); // (var4++)=3,(var4)=4
System.out.println(var5); // (++var2)=4,7%4=3
System.out.println(var5++); //3 (postfix)
System.out.println(var5); //(var5++)=3, (var5)=4
System.out.println(++var5);// 5 (prefix)


int num1 = 4;         
int num2 = 8;
int num3 = 50;
int num4 = 100;
num2 += num1; //num2=(num2+num1)=8+4=12
num3 += num2; //num3=(num3+num2)=50+12=62
num4 += num3; //num4=(num4+num3)=100+62=162
num4 += num3 += num2 += num1; //num4=(162+62+12+4)=240
System.out.println(num1); //4
System.out.println(num2); // num2=(num2+num1)=12+4=16
System.out.println(num3); // num3=(num3+num2)=62+16=78
System.out.println(num4); // num4=(num4+num3)=78+162=240


Not only for integers,But also for Strings we can use operators.

String first = "hello";   //here we use "" because,this is a string
String second = " world";
String together = "";
together += first; //together=(together+first)=hello
together += second; //together=(together+second)=hello world
System.out.println(together) //hello world

Here are few examples of conclusion in operators in java,that we discussed so far,Try them.


int i,j,m,n,k;
float f,g;
char c='x';
System.out.println(k+12*m+j+m%n); //(2+(12*5)+2+0)=64
System.out.println(-12L*(g-k)+'c'); //
System.out.println(i++*n*++j); //(2*5*3)=30
System.out.println(k*m/(j*n)); //(2*5/(2*5))=0
System.out.println(k*m-n%g); // (2*5-(1)=9)
System.out.println(m/k/n*j); // (5/2/(5*2))=0
System.out.println(k==2); //true
System.out.println(k=2); // 2
System.out.println(m-++n); //(5-6)=-1
System.out.println(k+12*m); //(2+(12*5))=62
System.out.println(m/j); //2
System.out.println(n%j); //1
System.out.println(m/j*j); //(5/(2*2))=1
System.out.println(f+10*5+g); //(12+50+4)=66.0
System.out.println(++i*n); //(3*5) =15//i=3=prefix
System.out.println(i++*n); //(3*5)=15 //i=3=postfix
int a=2,b=3,c=4,d=5;
float k=4.3f;
System.out.println(--b*a+c*d--); // (2*2)+(4*5)=24
System.out.println(a++); // 2(postfix)
System.out.println(c=c++); // 4(postfix)
System.out.println(++c); // 5(prefix)
System.out.println(c=++c*a++);// 6*3=18

Here I discussed mainly about assignment operator.If you guys follow my previous articles in operators in Java,you can have a better idea about operators.With in my next article I hope to discuss about last part of operators,Bit wise operators.Keep in touch.