Basic Incrementing Triangle Pattern (Inverted, init = 3)

Program to Print Basic Incrementing Triangle Pattern (Inverted, init = 3)

PRINTING PATTERN:

3
44
555
6666
            

PREREQUISITE:

Basic knowledge of Java language and loops.

ALGORITHM:

1. Initialize a variable (let's call it 'init') to 3. This will be the starting number for the pattern.
2. Determine the number of rows to print based on the value of 'init'. The number of rows will be equal to 'init'.
3. Initialize a loop that runs from 1 to 'init' (inclusive) to iterate through each row.
4. For each row (let's call the current row index 'i'), initialize another loop that runs from 1 to 'i' (inclusive) to print the numbers in that row.
5. Inside the inner loop, print the current value of 'i' for each column in that row.
6. After finishing the inner loop for a row, print a newline character to move to the next row.
7. Repeat steps 3 to 6 until all rows are printed.

Code in Java:

public class IncrementingTrianglePatternInverted {
    public static void main(String[] args) {
        int init = 3;  // Starting number

        // Loop to print the incrementing triangle pattern (inverted)
        for (int i = 1; i <= init; i++) {  // Loop for each row
            for (int j = 1; j <= i; j++) {  // Loop for each column in the current row
                System.out.print(i);  // Printing the current row number
            }
            System.out.println();  // New line after each row
        }
    }
}
            

Output:

3
44
555
6666