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);
Views 15
Answer:
- Loop Execution: The loop will execute 3 times (
i = 3, 4, 5
). - Output:
k = 60
(sincek = 1 * 3 * 4 * 5
)
Related Articles:
This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of Java Programming Language, click the links and dive deeper into this subject.
Join Our telegram group to ask Questions
Click below button to join our groups.