What will be displayed when the following code is executed?
int number = 6;
while (number > 0) {
number -= 3;
System.out.print(number + " ");
}
a. 6 3 0
b. 6 3
c. 3 0
d. 3 0 -3
e. 0 -3
c number is 6 before the loop. In the first iteration, number is reduced to 3 . In the second iteration, number is reduced to 0 . The loop is now finished. The loop body is executed 2 times for number 6 and 3 . Since number is reduced by 3 before the print statement. 3 and 0 and displayed. So, the correct answer is C.
You might also like to view...
The Check for ________ commands enable you to uncover issues that may cause difficulties for viewers
Fill in the blank(s) with correct word
A(n) ________ is a document that defines all of the known resources, actions, tasks, systems, and data that are required to manage a business recovery process in the event of a significant business interruption
Fill in the blank(s) with correct word