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

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

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

向下的三角形星形图案意味着我们要打印一个朝下的三角形意味着底面朝上,默认情况下,方向是向左的,因此要打印的所需三角形应如下所示

* * * *
* * *
* *
*

例子

Java
// Java Program to Print Lower Star Triangle Pattern
  
// Main class
public class GFG {
  
    // Main driver method
    public static void main(String[] args)
    {
        // Nested 2 for loops for iteration over the matrix
  
        // Outer loop for rows
        int rows = 9;
        for (int a = rows - 1; a >= 0; a--) {
  
            // Inner loop for columns
            for (int b = 0; b <= a; b++) {
  
                // Prints star and space
                System.out.print("*"
                                 + " ");
            }
  
            // By now we are done with single row so new
            // line
            System.out.println();
        }
    }
}


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