Line | Description |
---|---|
3 | Creates the variables i and j of type integer |
5 | for loop with the range 1 to 8 and a counter variable called i . i is incremented by 1 in each loop pass. |
6 | A second for loop, nested in the first one with the range 1 to i and the counter variable j . j is incremented by 1 in each loop pass. |
7 | The counter variable i of the first for loop is output.In the first loop pass only a 1 is output, because the second loop has the range 0 – 1. On the second pass, the counter variable of the first loop ( i ) is 2. Consequently, the second for loop has the range 0 – 2, which is why the number 2, 2 times is output. The number 3, 3 times and so on |
9 | Each time the second for loop is processed, a new line is printed |
class Pattern {
public static void main(String[] args) {
int i, j;
for (i = 1; i <= 8; i++) {
for (j = 1; j <= i; j++) {
System.out.print(i);
}
System.out.println();
}
}
}
1
22
333
4444
55555
666666
7777777
88888888