打印三角形
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调试代码
![](https://img2023.cnblogs.com/blog/2220408/202303/2220408-20230320174458776-17381646.png)