有人可以幫幫我用JAVA的draw來畫此圖嗎?

寫一類別可以show出此圖

有一 method 為 draw()

*

**

***

****

*****

******

*****

****

***

**

*

Update:

我想了一周,只會寫上半部,但下半部反過來,我卻寫不出來,所以請大大們幫幫我!

2 Answers

Rating
  • Dark
    Lv 4
    1 decade ago
    Favorite Answer

    public class test

    {

    public void draw(){ //method draw()

    for(int i=1;i<=5;i++){

    for(int j=1;j<=5-i;j++){

    System.out.print(" ");

    }

    for(int j=1;j<=i;j++){

    System.out.print("*");

    }

    System.out.println();

    }

    for(int i=4;i>=1;i--){

    for(int j=1;j<=5-i;j++){

    System.out.print(" ");

    }

    for(int j=1;j<=i;j++){

    System.out.print("*");

    }

    System.out.println();

    }

    }

    public static void main (String [] argv){

    test a =new test();

    a.draw();

    }

    }

    Source(s): me
  • 志明
    Lv 5
    1 decade ago

    public class F99690017 {

    public static void main(String args[]) {

    int count = 1;// 起初與結束的星星,1代表1顆星

    int step = 1;// 每次增加幾顆星

    int max = 5;// 最多不能超過的星數

    int min = count;// 勿改!

    boolean status = true;// 勿改!

    while (true) {

    for (int i = 0; i < max-count; i++) {

    System.out.print(" ");

    }

    for (int i = 0; i < count; i++) {

    System.out.print("*");

    }

    if (status) {

    count += step;

    System.out.println();

    if (count > max) {

    status = false;

    count -= step * 2;

    }

    } else {

    count -= step;

    System.out.println();

    if (count < min) {

    break;

    }

    }

    }

    }

    }

    2009-11-20 10:05:22 補充:

    菱形我都寫給你了,真不知你在想什麼

    Source(s): mySelf
Still have questions? Get your answers by asking now.