0
What about this one? From sololearn code challenges Ingot few minutes ago. The correct answer must be 1, since x<x*x.
public class Program { public static void main(String[] args) { int i; for ( i=6; i<i*i; i--); System.out.println(i); } }
5 Respostas
+ 3
The for loop itself is not doing anything because there is a semicolon at the end of the line. Just changing the variable.
The indentation of the println is visually confusing, but it is executed only once.
What happens in the loop: as long as i is smaller than its square, keep decrementing i
6 < 36 ✔️
5 < 25 ✔️
4 < 16 ✔️
3 < 9 ✔️
2 < 4 ✔️
1 < 1 ✖️
At this point loop is stopped and the last value of i = 1 is printed.
+ 2
Yes.
1 < 1 false loop stops.
And prints 1
+ 2
Ok. I agree with you.
+ 1
What is challenge question actually? use description place for details..
+ 1
That is the challenge. The question is what is the output or the value of i after execution.