[Solved] Post increment JAVA


for(i=0;i<=100;i++)

This will do i = 0 -> i = 100, which 101 iterations. If you want only 100 iterations exactly, you’d need either of these:

for (i = 0; i < 100; i++) // note: < only: 0 -> 99 = 100 iterations.
for (i = 1; i <= 100; i++) // note: change of starting point: 1 -> 100 = 100 iterations

comment followup:

This code:

j = j++;

is the functional equivalent of

temp = j;  // save current value of j, e.g 0 
j = j + 1; // increment j, e.g. j becomes 1
j = temp;  // put saved value into j, e.g. j goes back to 0

If you’d done:

j = ++j;

then it’d be

temp = j
temp = temp + 1
j = temp

or literally just

j = j + 1

1

solved Post increment JAVA