打印三角形及Debug模式

打印三角形

package test.operator;

public class printTriangle {
    public static void main(String[] args) {
        for (int i = 1; i <= 5; i++) {
            for(int j=5;j>=i;j--){//打印空格三角形
                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();
        }
    }
}

打印菱形

package test.operator;

public class printDiamond {
    public static void main(String[] args) {
        for (int i = 1; i <= 5; i++) {
            for (int j = 5; j >= i; j--) {//打印空格左直角三角形
                System.out.print(" ");
            }
            for (int j = 1; j <= i; j++) {//打印左直角三角形
                System.out.print("*");
            }
            for (int j = 5; j >=i; j--) {//打印右直角三角形,形成菱形
                System.out.print("*");
            }
            System.out.println();
        }
    }
}

Debug调试代码

posted @ 2023-03-20 17:44  chengh0618  阅读(11)  评论(0编辑  收藏  举报