Question
What is the output of the following Java code? Â
 public class LoopTest {     public static void main(String[] args) {       int x = 0;       while (x < 5) {         x++;         if (x == 3) {           break;         }       }       System.out.println(x);     }   }Solution
Initial: x = 0 Â Â Loop 1: x < 5 (0 < 5) is true. x becomes 1. x == 3 (1 == 3) is false. Â Â Loop 2: x < 5 (1 < 5) is true. x becomes 2. x == 3 (2 == 3) is false. Â Â Loop 3: x < 5 (2 < 5) is true. x becomes 3. x == 3 (3 == 3) is true. break executes. Â Â The loop terminates. System.out.println(x) prints 3.
24Â Â Â 25Â Â Â Â 34Â Â Â Â 59Â Â Â 108Â Â Â ?
2120 1976 2097 1997 ? 2014
...9060 5685 3488 2157 1428 1077
1Â Â Â Â 1Â Â Â Â 8Â Â Â Â 4Â Â Â Â 27Â Â Â Â 9Â Â Â Â ?
...34, 18, 20, ?, 70, 180
324 322 640 1914 7648 ? 229368
...3601 3602 1803 604 154 36
...32, 8, 4, ?, 3, 3.75
89Â Â Â Â Â 78Â Â Â Â Â 74Â Â Â Â Â 67Â Â Â Â Â 63Â Â Â Â ?
69    119    156    ?     199    209