Answers to Self-Test Questions
-
0 1 2 3 4 count after loop = 5
2. Yes, the body of a
while
loop can execute zero times. No, the body of ado-while
loop must execute at least once.-
0 count after loop = 1
-
Scanner keyboard = new Scanner(System.in); int number; System.out.println("Enter a whole number:”); number = keyboard.nextInt(); System.out.println("You entered " + number); while (number > 0) { System.out.println("Enter a whole number:”); number = keyboard.nextInt(); System.out.println("You entered " + number); } System.out.println("number after loop = " + number);
5. This is an infinite loop. The
println
statement after the loop will never be executed. The output begins0 −1 −2 −3 . . .
-
while (population <= 0) { System.out.println("Population ...
Get Java: An Introduction to Problem Solving and Programming, 8th Edition now with the O’Reilly learning platform.
O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.