What will be the result of attempting to compile and run the following program?
public class Main{ public static void main (String args []){ boolean b = false; int i = 1; do{ /*from ww w.j a v a 2 s . c o m*/ i++ ; } while (b = !b); System.out.println ( i ); } }
Select 1 option
Correct Option is : C
A. is wrong.
It is perfectly valid because b = !b; returns a boolean, which is what is needed for while condition.
The 'do {} while()
' loop executes at least once because the condition is checked after the iteration.