Java Code Example: simple pattern

This is an example of a Java program that prints a pattern of numbers. The program uses nested for loops to iterate over the rows and columns of the pattern and prints the value of i for each position in the pattern.

Here’s a breakdown of how the program works:

  • The outer loop iterates over the rows of the pattern, from 1 to 8.
  • The inner loop iterates over the columns of the pattern, from 1 to the current row number i.
  • For each position in the pattern, the value of i is printed using the System.out.print() method.
  • After printing all the values in the current row, a newline character is printed using the System.out.println() method to move to the next row.
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();
		}
	}
}
Output
1
22
333
4444
55555
666666
7777777
88888888