Java Program to Print a Pattern of Left Triangle Star

Last Updated On Friday 21st Jan 2022

triangle pattern in java

Input any positive integer and it will print the pattern.

Example 1 : left triangle java

	public class LeftTriangleStar {
    public static void main(String[] args) {
        int i, j, row = 6;
        for (i = 0; i < row; i++) {
            for (j = 2 * (row - i); j >= 0; j--) {
                System.out.print(" ");
            }
            for (j = 0; j <= i; j++) {
                System.out.print("* ");
            }
            System.out.println();
        }
    }
}
	

Example 2 : left triangle java

	public class LeftTri {
    public static void main(String[] args) {
        int k = 6;
        StarPattern(k);
    }
    public static void StarPattern(int n) {
        for (int i = 0; i < n; i++) {
            for (int j = n - i; j >= 0; j--) {
                System.out.print("* ");
            }
            System.out.println();
        }
    }
}
	
	//             * 
//           * * 
//         * * * 
//       * * * * 
//     * * * * * 
//   * * * * * *