Left Triangle Star Pattern in Java

thumbnail

In this tutorial, you will learn to create left triangle star pattern in java.

Example 1:

package patternchallenge;

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

The output will be:

*
**
***
****
*****

Example 2:

package patternchallenge;
public class PatternChallenge {
    public static void main(String[] args) {
        leftTriangle2 (5);
    }
    public static void leftTriangle2 (int n){
        for(int i=0; i<n; i++){           
            for(int j=0; j<=i; j++){       
                System.out.print("*"); // print star
            }           
            System.out.println(); // ending line after each row
        }
    }
}

The output will be:

*
**
***
****
*****
Back To Top