Simple Triangle Pattern in Java.

Java Programming Language Decision Making and Looping in java (Article) Decision Making and Looping in java (Program)

33

Given Input:

 int rows = 5;

Expected Output:

*
* *
* * *
* * * *
* * * * *
Press any key to continue . . .

Program:

class TrianglePattern {
    public static void main(String args[]) {
        int rows = 5;
        
        for (int i = 1; i <= rows; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print("* ");
            }
            System.out.println();
        }
    }
}

Output:

*
* *
* * *
* * * *
* * * * *
Press any key to continue . . .

This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.