Give:
public class MyFive {
static void main(String[] args) {
short ii;
short jj = 0;
for (ii = kk; ii > 6; ii -= 1) { // line x //
jj++;
}
System.out.println(“jj = ” + jj);
}
}
What value should replace kk in line x to cause jj = 5 to be output?
A.
-1
B.
1
C.
5
D.
8
E.
11
Explanation:
We need to get jj to 5. It is initially set to 0. So we need to go through the for loop 5 times. The for loops ends when ii > 6 and ii decreases for every loop. So we need to initially set ii to 11. We set kk to 11.
E
The Answer is E.
The loop has to run 5 times to increment the variable jj from 0 up to 5.