Given:
public class DoWhile {
public static void main (String [] args) {
int ii = 2;
do {
System.out.println (ii);
} while (–ii);
}
}
What is the result?
A.
2
B.
2
C.
null
D.
an infinite loop
E.
compilation fails
Explanation:
The line while (–ii); will cause the compilation to fail.
–ii is not a boolean value.
A correct line would be while (–ii>0);
E
Incompatible types, // while(boolean)is only valid.
The Answer is E.
The condition in a do-while loop must evaluate to a boolean true or false, not an integer.