Given:
public class DoCompare4 {
public static void main(String[] args) {
String[] table = {“aa”, “bb”, “cc”};
int ii =0;
do
while (ii < table.length)
System.out.println(ii++);
while (ii < table.length);
}
}
What is the result?
A.
0
B.
0
1
2
C.
0
1
2
0
1
2
0
1
2
D.
Compilation fails
Explanation:
table.length is 3. So the do-while loop will run 3 times with ii=0, ii=1 and ii=2.
The second while statement will break the do-loop when ii = 3.
Note: The Java programming language provides a do-while statement, which can be expressed as
follows:
do {
statement(s)
} while (expression);