consider the following code segment.\nint value = 15;\nwhile (value < 28) {\n system.out.println(value);\n…

consider the following code segment.\nint value = 15;\nwhile (value < 28) {\n system.out.println(value);\n value++;\n}\nwhat are the first and last numbers output by the code segment?\na 15 (first), 27 (last)\nb 15 (first), 28 (last)\nc 16 (first), 27 (last)\nd 16 (first), 28 (last)
Answer
Explanation:
Step1: Analyze initial value
The variable value is initialized to 15. The while loop condition is value < 28. The first - thing the loop does is print the value of value. So the first number printed is 15.
Step2: Analyze loop increment and termination
The value++ statement increments the value of value by 1 after each print. The loop will continue as long as value < 28. When value reaches 27, it will be printed and then incremented to 28. At this point, the loop condition value < 28 fails and the loop terminates. So the last number printed is 27.
Answer:
A. 15 (First), 27 (Last)