练习:打印三角形

练习:打印三角形

public class Demo1 {
    public static void main(String[] args) {
         //最外侧for循环
        for (int i = 1; i <= 5; i++) {
            //以下皆为内侧for循环,(这里最外侧for循环每循环一次,需要走完内侧所有满足条件的成员并输出
            for (int j = 5; j >= i; j--) {
                //1. i: 1  j: 5
                //2. i: 1  j: 4    
                //3. i: 1  j: 3  ...;满足条件就依此类推
                System.out.print(" ");  //这里会输出不换行的空格
            }
            for (int j = 1; j <=i; j++) {
                System.out.print("*"); //这里会输出不换行的 " * "
                }
            for (int j = 1; j < i; j++) {
                System.out.print("*");
            }
               System.out.println();//一轮循环结束,换行
           }
        }
    }
posted @ 2021-04-01 21:21  小老豆  阅读(63)  评论(0)    收藏  举报