1 回答

TA貢獻(xiàn)1846條經(jīng)驗(yàn) 獲得超7個贊
乍一看,您似乎沒有考慮打印星星后出現(xiàn)的空間。嘗試像這樣修改代碼:
private static void printStars(int rows, int columns)
{
int stars = 1;
while (rows > 0) {
int spaces = rows;
for (int i = 1; i <= columns; i++) {
for (int sp = spaces; sp >= 1; sp--) {
System.out.print(" ");
}
for (int st = stars; st >= 1; st--) {
System.out.print("*");
}
for (int sp = spaces; sp >= 1; sp--) {
System.out.print(" ");
}
}
System.out.println();
stars += 2;
rows--;
}
}
添加回答
舉報