Nested Loops
Nested Loops
Nested Loops
Output:
1
2
3
4
2
4
6
8
3
6
9
12
4
8
12
16
5
10
15
20
Solution
Answer:
....1
...22
..333
.4444
55555
Exercise
Modify the previous code to produce this output:
....1
...2.
..3..
.4...
5....
Solution
for (int line = 1; line <= 5; line++) {
for (int j = 1; j <= (5 - line); j++){
System.out.print(".");
}
System.out.print(line);
for (int j = 1; j <= (line - 1); j++) {
System.out.print(".");
}
System.out.println();
}
Common Mistakes