程式需要被幫忙修改一下

2009-04-01 8:41 am
public class sample14{
public static void main(String args[]){
int i=1;int j=0;


do{
do{
System.out.print("*");
j++;
}while(j<i);
i++;System.out.print("\n"); j=0;
}while(i<4);

}
}


以上程式只會顯示
*
**
***

那要怎修改讓它顯示
*
**
***
**
*

想嚕許久還是改不出來~~
請幫忙一下~~謝謝

回答 (1)

2009-04-01 2:48 pm
✔ 最佳答案
public class Main {
public static void main(String args[]){
int i=1;int j=0;

do{
do{
System.out.print("*");
j++;
}while(j<i);
i++;System.out.print("\n");
j=0;
}while(i<4);

i -= 2;
do{
do{
System.out.print("*");
j++;
}while(j<i);
i--;
System.out.print("\n");
j=0;
}while(i>0);
}
}

// Note that the loops I have added is just like yours except they
// decrement instead of increment


收錄日期: 2021-04-30 12:54:50
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20090401000010KK00465

檢視 Wayback Machine 備份