Artem H.

asked • 04/25/21

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.

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);


1 Expert Answer

By:

Patrick B. answered • 04/25/21

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.