+ 5

What's the difference between x=x+2 and x++

for(int x=0; x<=10; x=x+2) { System.out.println(x); }

22nd Aug 2017, 8:45 AM
Sampson Joshua (Jozy)
Sampson Joshua (Jozy) - avatar
6 Answers
+ 10
x=x+2 //increments value everytime by 2 x++ //increments value by 1
22nd Aug 2017, 9:07 AM
P R
P R - avatar
+ 1
x=x+2 is incremented by 2and x is incremented by 1.
27th Sep 2017, 9:45 AM
GOWTHAMI BOJJA
GOWTHAMI BOJJA - avatar
0
use the first if you are not sure what 2nd does
22nd Aug 2017, 10:06 AM
Gao Xiangshuai
Gao Xiangshuai - avatar
0
if you use x=x+1 then no difference
1st Oct 2017, 8:35 AM
Sachin Kumar Gupta
Sachin Kumar Gupta - avatar