如何用java语句打印菱形

2020-05-25 科技 74阅读
public class Diamond {
public static void main(String[] args) {
final int size = 4;
for (int i = 1; i <= size; i++) {
for (int j = i; j < size; j++) {
System.out.print(" ");
}
for (int k = 1; k <= 2 * i - 1; k++) {
System.out.print("*");
}
System.out.println();
}
for (int i = size - 1; i >= 1; i--) {
for (int j = 1; j <= size - i; j++) {
System.out.print(" ");
}
for (int k = 2 * i - 1; k > 0; k--) {
System.out.print("*");
}
System.out.println();
}
}
}
------------------------
*
***
*****
*******
*****
***
*
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com