java如何编写出菱形的代码_java编写菱形代码

菱形代码

public class Diamond {

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();

}

for (int i = 1; i <= 5; i++) {

for (int j = 1; j <= i; j++) {

System.out.print(" ");

}

for (int j = 5; j >= i ; j--) {

System.out.print("*");

}

for (int j = 5; j > i; j--) {

System.out.print("*");

}

System.out.println();

}

}

}

效果图:

java如何编写出菱形的代码_java编写菱形代码_第1张图片

标签:java,int,System,--,菱形,println,print,编写,out

来源: https://blog.csdn.net/weixin_45672607/article/details/112058628

你可能感兴趣的:(java如何编写出菱形的代码)