+ 3
why its output is zero?
int j=0; for(int i=0;i<100;i++) j=j++; System.out.println(j);
10 Answers
+ 8
Why don't you just save it in the code playground and run it? :)
+ 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);
+ 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.
+ 1
well its 0.
0
100
0
its answer is 0
0
1 to 99
0
1
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
0
0