+ 2
I am little bit confused about this equation. How this code result to 6 ?
int i; for(i = 1; i <=5; i++); System.out.print(i);
6 Respostas
+ 2
Your reasoning is found in this:
i <=5;
^Varible 'i' starts off at 0 and is ending at 5 (less than-equal to). 0-5 is 6 spaces. If you did i < 5 then it would display 5 numbers (0-4) rather than 6 numbers.
Also, you're declaring variable 'i' twice, so you'll prob run into compile issues. Remove 'int i' from before the loop.
+ 4
@Xan
"Varible 'i' starts off at 0 and is ending at 5 (less than-equal to). 0-5 is 6 spaces. If you did i < 5 then it would display 5 numbers (0-4) rather than 6 numbers. "
Also, put a check next to Xan's answer instead of placing your own comment as the correct answer to the question/thread.
+ 3
6 is never output. I think you mean why is System.out.print(i) called 6 times.
it's the <= which means Less Than OR Equal.
5 is less than or equal to 5.
Also, no need to declare i twice.
+ 2
https://code.sololearn.com/c5tlY2u9gyI8/?ref=app
I think Kent it was challenge question so if you want output 6: then this is may be coding question
+ 1
sorry...i edit one that need corrections..
thank you for your answers..i understand it now...👍👍
0
I believe Jakob is incorrect. I is 6 by the time it is printed because the i++ in the loop adds 1 once after the final i<=5 evaluation.
The i=1 part of the for loop resets i to 1 when the for loop starts the first time