|登录 |注册

查看: 898|回复: 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
问题已解~~谢谢你
您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2026-1-1 07:21 AM , Processed in 0.091575 second(s), 21 queries .

Powered by Discuz! X2.5 © 2001-2012 Comsenz Inc.

本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved

Dedicated Server powered by iCore Technology Sdn. Bhd.

合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部