+ 3

why its output is zero?

int j=0; for(int i=0;i<100;i++) j=j++; System.out.println(j);

27th Mar 2018, 5:50 PM
Abhishek Yadav
Abhishek Yadav - avatar
10 Answers
+ 8
Why don't you just save it in the code playground and run it? :)
27th Mar 2018, 5:55 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 3
To explain, you're assign j++ to j, instead of only putting j++. As such, each loop it's reassigning j++ to the variable j, so it never goes anywhere, thus it remains 0. Do this instead: int j=0; for(int i=0;i<100;i++) j++; System.out.println(j);
27th Mar 2018, 6:01 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 3
If you're attempting to quiz users, then please utilize the quiz-factory rather than posting a thread on the Q&A forum. Thanks.
2nd Apr 2018, 3:28 PM
Fox
Fox - avatar
+ 1
well its 0.
27th Mar 2018, 5:59 PM
cHiRaG GhOsH
cHiRaG GhOsH - avatar
0
100
27th Mar 2018, 5:55 PM
TurtleShell
TurtleShell - avatar
0
its answer is 0
27th Mar 2018, 6:00 PM
Abhishek Yadav
Abhishek Yadav - avatar
0
1 to 99
28th Mar 2018, 6:10 AM
peerzada owais
peerzada owais - avatar
0
1
28th Mar 2018, 7:44 AM
Rian Rian
0
99 is the answer as the loop will go on and there are no curly brackets therefore the value of j will keep on increasing as it is in the loop and the loop goes on till 99 therefore the output will be 99
28th Mar 2018, 8:09 AM
Sainssh
Sainssh - avatar
0
0
28th Mar 2018, 5:26 PM
jyothi