请用java语言输出一个菱形
时间: 2023-03-14 19:53:58 浏览: 82
我可以用Java语言向您输出一个菱形:
public class Diamond {
public static void main(String[] args) {
int size = 5;
for (int i = 0; i < size; ++i) {
for (int j = 0; j < size - 1 - i; ++j) {
System.out.print(" ");
}
for (int j = 0; j < 2 * i + 1; ++j) {
System.out.print("*");
}
System.out.println();
}
for (int i = size - 2; i >= 0; --i) {
for (int j = 0; j < size - 1 - i; ++j) {
System.out.print(" ");
}
for (int j = 0; j < 2 * i + 1; ++j) {
System.out.print("*");
}
System.out.println();
}
}
}
阅读全文