Java Reference
In-Depth Information
19. What is the output of the following loop?
for (int i = 1; i <= 3; i++)
System.out.println("How many lines");
System.out.println("are printed?");
20. What is the output of the following loop?
System.out.print("T-minus ");
for (int i = 5; i >= 1; iā€”ā€”) {
System.out.print(i + ", ");
}
System.out.println("Blastoff!");
21. What is the output of the following sequence of loops?
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= 10; j++) {
System.out.print((i * j) + " ");
}
System.out.println();
}
22. What is the output of the following sequence of loops?
for (int i = 1; i <= 10; i++) {
for (int j = 1; j <= 10 ā€” i; j++) {
System.out.print(" ");
}
for (int j = 1; j <= 2 * i ā€” 1; j++) {
System.out.print("*");
}
System.out.println();
}
23. What is the output of the following sequence of loops?
for (int i = 1; i <= 2; i++) {
for (int j = 1; j <= 3; j++) {
for (int k = 1; k <= 4; k++) {
System.out.print("*");
}
System.out.print("!");
}
System.out.println();
}
24. What is the output of the following sequence of loops? Notice that the code is the same as that in the previous exer-
cise, except that the placement of the braces has changed.
for (int i = 1; i <= 2; i++) {
for (int j = 1; j <= 3; j++) {
for (int k = 1; k <= 4; k++) {
Search WWH ::




Custom Search