✏️ Explanatory Question

Analyze the following program segment and determine how many times the loop will be executed and what will be the output of the program segment.

int k = 1;
int i = 2;
while(++i < 6) {
    k *= i;
}
System.out.println(k);

👁 99 Views
📘 Detailed Answer
🟢 Easy
💡

Answer with Explanation

  • Loop Execution: The loop will execute 3 times (i = 3, 4, 5).
  • Output: k = 60 (since k = 1 * 3 * 4 * 5)