No the answer is B. Iterate until ii is no longer smaller than jj, so when I is 7 or higher. At the end of one iteration, add 2 to ii. This is after the print statement.
So it prints 0 , increments to 2
Then it prints 2 , increments to 4
Then it prints 4 , increments to 6
Then it prints 6 , increments to 8
Then it is no longer smaller than 7, so the loop ends.
Option C.
public class Test {
public static void main(String[] args) {
int ii = 0;
int jj = 7;
for (ii = 0; ii < jj – 1; ii = ii +2) {
System.out.print(ii + " ");
}
}
}
Output:
0 2 4
Explanation:
the loop will break after the 3rd run, because "ii < jj – 1" which is " ii < 6"!
C
Answer is D
Because variable ii is already defined in method main
it won’t print 6 as ii<6 it will come out of the loop
No the answer is B. Iterate until ii is no longer smaller than jj, so when I is 7 or higher. At the end of one iteration, add 2 to ii. This is after the print statement.
So it prints 0 , increments to 2
Then it prints 2 , increments to 4
Then it prints 4 , increments to 6
Then it prints 6 , increments to 8
Then it is no longer smaller than 7, so the loop ends.
The result is “0 2 4 6 “
C