What's the output of the following code?
public class Main { public static void main(String[] args) { int i = 10; do while (i < 15) i = i + 20; while (i < 2); System.out.println(i); } }
B
The condition specified in the do-while loop evaluates to false because 10<2 evaluates to false.
But the control enters the do-while loop because the do-while loop executes at least once.
The while evaluates to true for the first iteration and adds 20 to i, making it 30.
public class Main { public static void main(String[] args) { int i = 10;// w ww .jav a 2 s .com do while (i < 15) i = i + 20; while (i < 2); System.out.println(i); } }