Home / Questions / 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);
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 to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation

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