Left Triangle Custom Pattern #1 in Java

thumbnail

In this tutorial, you will learn to create custom pattern #1 in java. You will create pattern with * and #. The implementation is show below.

package patternchallenge;
public class PatternChallenge {
    public static void main(String[] args) {
        PatternTriangle customTriangle = new PatternTriangle();
        customTriangle.leftTriangleCustom1(5);
    }
}
package patternchallenge;
public class PatternTriangle {
    public void leftTriangleCustom1(int n){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=i;j++){
                if(i%2==1){
                    System.out.print("*");
                } else {
                    System.out.print("#");
                }
            }
            System.out.println("");
        }
    }
}

The output will be:

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