帮我用JAVA输出一个菱形
时间: 2023-03-13 18:30:47 浏览: 93
用JAVA语言输出菱形
很高兴为您服务。我将用Java编写代码来输出一个菱形:
public class Diamond {
public static void main(String[] args) {
int count = 0;
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= 5 - i; j++) {
System.out.print(" ");
}
while (count != (2 * i - 1)) {
System.out.print("*");
count++;
}
count = 0;
System.out.println();
}
for (int i = 4; i >= 1; i--) {
for (int j = 1; j <= 5 - i; j++) {
System.out.print(" ");
}
count = 0;
while (count != (2 * i - 1)) {
System.out.print("*");
count++;
}
System.out.println();
}
}
}
阅读全文