Skip to content
Related Articles

Related Articles

Java Program to Print Left Triangle Star Pattern

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 06 Jun, 2022

In this article, we will learn about printing Left Triangle Star Pattern.

Examples:

Input : n = 5
Output: 
           * 
         * * 
       * * * 
     * * * * 
   * * * * * 

Left Triangle Star Pattern:

Java




import java.io.*;
 
// java program for left triangle
public class GFG {
    // Function to demonstrate printing pattern
    public static void StarleftTriangle(int k)
    {
        int a, b;
 
        // 1st loop
        for (a = 0; a < k; a++) {
 
            // nested 2nd loop
            for (b = 2 * (k - a); b >= 0; b--) {
                // printing spaces
                System.out.print(" ");
            }
 
            // nested 3rd loop
            for (b = 0; b <= a; b++) {
                // printing stars
                System.out.print("* ");
            }
 
            // end-line
            System.out.println();
        }
    }
 
    // Driver Function
    public static void main(String args[])
    {
        int k = 5;
        StarleftTriangle(k);
    }
}

Output

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

Time Complexity: O(k2), where k represents the given input.
Auxiliary Space: O(1), no extra space is required, so it is a constant.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!