Java 实例 – 打印倒立的三角形

3081 1
LZH实名认证 2022-3-20 13:50:47 | 显示全部楼层 |阅读模式
打印倒立的三角形。

实例
public class InvertedTriangle {
    public static void main(String[] args) {
         //打印倒立的三角形
        for (int m = 1; m <= 4; m++) {
            //打印空格
            for (int n = 0; n <= m; n++) {
                System.out.print(" ");
            }
            //打印*
            for (int x = 1; x <= 7 -2 * (m - 1); x++) {
                System.out.print("*");
            }
            System.out.println();
        }        
    }
}
输出结果:

  *******
   *****
    ***
     *
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

中国红客联盟公众号

联系站长QQ:5520533

admin@chnhonker.com
Copyright © 2001-2026 Discuz Team. Powered by Discuz! X3.5 ( 粤ICP备13060014号 )|天天打卡 本站已运行