Given:
public class DoCompare1 {
public static void main(String[] args) {
String[] table = {"aa", "bb", "cc"};
for (String ss: table) {
int ii = 0;
while (ii < table.length) {
System.out.println(ss + ", " + ii);
ii++;
}
}
How many times is 2 printed as a part of the output?
A.
Zero
B.
Once
C.
Twice
D.
Thrice
E.
Compilation fails.
Explanation:
The for statement, for (String ss: table), is executed one time for each of the three elements in table.
The while loop will print a 2 once for each element.
Output:aa, 0
aa, 1
aa, 2
bb, 0
bb, 1
bb, 2
cc, 0
cc, 1
cc, 2
Actually E, main metod not enclosed with }
d