What is the result?

Given:

public class DoWhile {
public static void main (String [] args) {
int ii = 2;
do {
System.out.println (ii);
} while (–ii);
}
}

What is the result?

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



Leave a Reply 2

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


Jazz

Jazz

E

Incompatible types, // while(boolean)is only valid.

James

James

The Answer is E.

The condition in a do-while loop must evaluate to a boolean true or false, not an integer.