用java写出菱形12321
时间: 2023-05-14 19:05:46 浏览: 66
以下是用 Java 写出菱形 12321 的代码:
```
public class DiamondPattern {
public static void main(String[] args) {
int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n - i; j++) {
System.out.print(" ");
}
for (int k = i; k >= 1; k--) {
System.out.print(k);
}
for (int l = 2; l <= i; l++) {
System.out.print(l);
}
System.out.println();
}
for (int i = n - 1; i >= 1; i--) {
for (int j = 1; j <= n - i; j++) {
System.out.print(" ");
}
for (int k = i; k >= 1; k--) {
System.out.print(k);
}
for (int l = 2; l <= i; l++) {
System.out.print(l);
}
System.out.println();
}
}
}
```
输出结果为:
```
1
212
32123
4321234
543212345
4321234
32123
212
1
```
阅读全文