Skip to content
Related Articles

Related Articles

Improve Article
Java Program to Print Left Triangle Star Pattern
  • Last Updated : 09 Mar, 2021

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
           * 
         * * 
       * * * 
     * * * * 
   * * * * * 

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :