|登录 |注册

登录
登录 注册
查看: 973|回复: 2
打印 上一主题 下一主题

问题已解~~

[复制链接]
seongchog
2011-9-16 03:33 PM
本帖最后由 seongchog 于 2011-9-16 06:09 PM 编辑

谢谢你们问题已解~~
Super-Tomato
2011-9-16 04:08 PM
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--)
seongchog
2011-9-16 06:10 PM
问题已解~~谢谢你
您需要登录后才可以回帖 登录 | 注册

回顶部