0
Noob。這應該會創建一個金字塔,但正如您所看到的,我無法正確設置我的x軸。我不知道該怎麼做。任何幫助?謝謝 - 基思。爲什麼我的金字塔不能正確堆疊?
import acm.graphics.*;
import acm.program.*;
public class Pyramid extends GraphicsProgram {
public void run()
{
double xCoord = 50;
double yCoord = 200;
double base = BRICKS_IN_BASE;
int cnt = 0;
while (cnt < base)
//for (int n = 0; n < base; n++)
{
for (int i = 0; i < base; i++)
{
add(new GRect(xCoord, yCoord, BRICK_WIDTH, BRICK_HEIGHT));
xCoord += BRICK_WIDTH;
}
base--;
yCoord -= BRICK_HEIGHT;
xCoord = ???????????????
}
}
private static final double BRICK_WIDTH = 10;
private static final double BRICK_HEIGHT = 12;
private static final double BRICKS_IN_BASE = 14;
private static final double X_BASE = 25;
}
你能告訴我們輸出不知何故?截圖? – hexafraction 2013-04-29 21:09:44
和預期的輸出。 – Guvante 2013-04-29 21:10:45
輸出,而不是一個有14個塊基的金字塔,然後13居中,然後12居中,等到1,而是14塊,然後它向上移動一條線並畫出一條13塊的線,但它坐在上一行的末尾(下面一行),而不是堆疊在頂部並繼續到1.我的問題是我無法讓金字塔正確堆疊。我懷疑這是xCoord軸的問題。 – 2013-04-29 21:14:22