用Java打印菱形,用了一个很low的写法。
for (int i = 4; i >= 1; i--) {
for (int j = 1; j <= i + 1; j++) {
System.out.print(" ");
}
for (int k = 4 - i; k >= 0; k--) {
System.out.print("* ");
}
for (int j = 1; j <= 4 - 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 k = 1; k <= 5 - i; k++) {
System.out.print("* ");
}
for (int j = 5 - i; j >= 0; j--) {
System.out.print("* ");
}
System.out.println();
}
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
Process finished with exit code 0