我需要畫一個數字的鑽石,例如與9高度:圖紙數字鑽石
1
222
33333
4444444
555555555
4444444
33333
222
1
我寫的代碼,我設法得到相同的鑽石,但星星。我想要這些數字。我怎樣才能做到這一點?以下是我迄今所做的:
for (int i = 1; i < 10; i += 2) {
for (int j = 0; j < 9 - i/2; j++)
System.out.print(" ");
for (int j = 0; j < i; j++)
System.out.print("a");
System.out.print("\n");
}
for (int i = 7; i > 0; i -= 2) {
for (int j = 0; j < 9 - i/2; j++)
System.out.print(" ");
for (int j = 0; j < i; j++)
System.out.print("b");
System.out.print("\n");
}
用'i'更換'stars'或'j'我要去承擔其用'j' – 3kings
http://codegolf.stackexchange.com/questions/8696/print-this-diamond - 不是你想要的,但一些有趣的方法... –