在控制台上打印以下图案的 Java 程序

2025 年 3 月 17 日 | 阅读 1 分钟
Java program to print the following pattern on the console

算法

  • 步骤 1: 开始
  • 步骤 2: 设置 coe=1, rows= 6。
  • 步骤 3: 设置 i=0。重复步骤 4 到步骤 11,直到 i
  • 步骤 4: 设置 space = 1。重复步骤 5 和步骤 6,直到 space<(rows ?i)
  • 步骤 5: 打印 ""
  • 步骤 6: ++space
  • 步骤 7: 设置 j=0。重复步骤 8 到步骤 9,直到 j<=i。
  • 步骤 8: IF(j==0||i==0)
                    设置 coe=1
                    ELSE
                    设置 coe=coe*(i-j+1) /j
                    打印 coe
  • 步骤 9: 设置 j = j+1
  • 步骤 10: 打印新行。
  • 步骤 11: 设置 i=i+1
  • 步骤 12:结束

程序

输出

Java program to print the following pattern on the console
下一个主题Java 程序