Java Reference
In-Depth Information
System.out.print(x + " ");
x = x + 10;
} while (x < 100);
b.
int max = 10;
do {
System.out.println("count down: " + max);
max--;
} while (max < 10);
c.
int x = 250;
do {
System.out.println(x);
} while (x % 3 != 0);
d.
int x = 100;
do {
System.out.println(x);
x = x / 2;
} while (x % 2 == 0);
e.
int x = 2;
do {
System.out.print(x + " ");
x *= x;
} while (x < 200);
f.
String word = "a";
do {
word = "b" + word + "b";
} while (word.length() < 10);
System.out.println(word);
g.
int x = 100;
do {
System.out.println(x / 10);
x = x / 2;
} while (x > 0);
h.
String str = "/\\";
do {
str += str;
} while (str.length() < 10);
System.out.println(str);
9.
Write a
do/while
loop that repeatedly prints a certain message until the user tells the program to stop. The
do/while
is
appropriate because the message should always be printed at least one time, even if the user types
n
after the first mes-
sage appears. The message to be printed is as follows:
She sells seashells by the seashore.
Do you want to hear it again?
y
She sells seashells by the seashore.
Search WWH ::
Custom Search