Excercises
12) a do-while loop
13) a while loop with a nested if-then branch
14) an if-then-else branch with a nested if-then-else-branch
15) an if-then branch with a nested while loop
16) a do-while loop with a nested do-while loop
17) an if-then-else branch with a nested do-while loop
18) an if-then branch with a nested if-then branch
19) a while loop with a nested while loop
20) a do-while loop with a nested if-then-esle branch
Excercises
i = 5;
while (i > 0) {
j = i;
while (j > 0) {
System.out.print("*");
--j;
}
--i;
System.out.println();
}
or
i = 5;
do {
j = i;
do {
System.out.print("*");
--j;
} while (j > 0);
--i;
System.out.println();
} while (i > 0);
62) i = 5;
while (i > 0) {
j = 5 - i;
while (j > 0) {
System.out.print(" ");
--j;
}
k = i;
while (k > 0) {
System.out.print("*");
--k;
}
--i;
System.out.println();
}
no. you will run into trouble on the first line becaue you will have to
print at least one space before the stars. However, you can do most of
it as follows.
i = 5;
do {
j = 5 - i;
while (j > 0) {
System.out.print(" ");
--j;
}
k = i;
do {
System.out.print("*");
--k;
} while (k > 0);
--i;
System.out.println();
} while (i > 0);
63)
64)
65) * * * * * *
* * * * *
* * * * * *
* * * * *
* * * * * *
* * * * *
* * * * * *
* * * * *
* * * * * *
Excercises