Basic Incrementing Triangle Pattern (init = 3)

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

PRINTING PATTERN:

6666
555
44
3
            

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 'init' down to 1 (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 IncrementingTrianglePattern {
    public static void main(String[] args) {
        int init = 3;  // Starting number

        // Loop to print the incrementing triangle pattern
        for (int i = init; i >= 1; 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:

6666
555
44
3