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

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

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

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

例子:

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

直角三角形星图:

Java
import java.io.*;
  
// Java code to demonstrate right star triangle
public class GeeksForGeeks {
    // Function to demonstrate printing pattern
    public static void StarRightTriangle(int n)
    {
        int a, b;
  
        // outer loop to handle number of rows
        // k in this case
        for (a = 0; a < n; a++) {
  
            // inner loop to handle number of columns
            // values changing acc. to outer 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;
        StarRightTriangle(k);
    }
}


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