📜  打印左三角形星形图案的Java程序

📅  最后修改于: 2022-05-13 01:55:47.918000             🧑  作者: Mango

打印左三角形星形图案的Java程序

在本文中,我们将学习打印左三角星形图案。

例子:

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

左三角星图:

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);
    }
}


输出
* 
         * * 
       * * * 
     * * * * 
   * * * * *