What is the result?

Given:
<code>
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);
}
</code>
What is the result?

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
12

C.
0
12012012

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);



Leave a Reply 2

Your email address will not be published. Required fields are marked *


Carlos

Carlos

this test don´t work, I failed the test, Don´t lost your time. Only 5 quest are in the test

sully

sully

need to remove line 8.