Java Code Example: pattern reverse

Code Explanation

LineDescription
3Creates the variables i and j of type integer
5for loop with the range 1 to 8 and a counter variable called i. i is incremented by 1 in each loop pass.
6A second for loop, nested in the first one with the range 8 to i and the counter variable j. j is decremented by 1 in each loop pass
7The counter variable i of the first for loop is output
9Each 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 = 8; j >= i; j--) {
				System.out.print(i);
			}
			System.out.println();
		}
	}
}
Output
11111111
2222222
333333
44444
5555
666
77
8