- 分享
- 0
- 人气
- 0
- 主题
- 7
- 帖子
- 4707
- UID
- 82675
- 积分
- 5108
- 阅读权限
- 22
- 注册时间
- 2007-6-18
- 最后登录
- 2021-7-27
- 在线时间
- 5767 小时
  
|
Question 1
Write an application that displays the following pattern as output. by using for loops.
You shall use the output statements that print a single asterisk (*), a single space or a single newline character. Maximum your use of repetition and minimize the number of output statement.
*********
*******
*****
***
*
***
*****
*******
*********
这是我的code:
int i, j;
for (i = 4; i > 0; i--) {
for (j = i; j < 4; j++) {
System.out.print(" ");
}
for (j = i; j > 0; j--) {
System.out.print("*");
}
for (j = i; j > 0; j--) {
System.out.print("*");
}
System.out.println();
}
}}
My Output:
********
******
****
**
seongchog 发表于 2011-9-16 03:33 PM 
樓主你在一開始就只設定 i=4 的情况下,當然會造成 Output 只出現 4 行的结果
for (i = 4; i > 0; i--) |
|