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 Answers
+ 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.