135k views
1 vote
For each of the following while loops, how many times will the loop execute its body? Remember that "zero," "infinity," and "unknown" are legal answers. a) int x = 1; while (x < 100) { System.out.print(x + " "); x += 10; } b) int max = 10; while (max < 10) { System.out.println("count down: " + max); max--; } c) int x = 250; while (x % 3 != 0) { System.out.println(x); } d) int x = 2; while (x < 200) { System.out.print(x + " "); x *= x; } e) String word = "a"; while (word.length() < 10) { word = "b" + word + "b"; } System.out.println(word); f) int x = 100; while (x > 0) { System.out.println(x / 10); x = x / 2; }

1 Answer

7 votes

Answer:

a.10 b. infinity c. infinity d. 3 e.5 f.7

Step-by-step explanation:

User Ricardus
by
6.0k points