A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© breaveheart 中级黑马   /  2013-7-18 17:08  /  1542 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

看了毕老师关于输出星形形状的代码,自己参照写了个数字塔形的供大家看看。
新手可能有疏漏,有好想法的欢迎大家批评建议。{:soso_e100:}

输出效果:
               

代码:
  1. class taxing
  2. {
  3. public static void main(String[] args)
  4. {
  5. int x,y,z;
  6. for(x=1;x<=4;x++)
  7. {
  8. for(y=7-x;y>=1;y--)
  9. {
  10. System.out.print(" ");
  11. }
  12. for(z=1;z<=x;z++)
  13. {
  14. System.out.print(z+" ");
  15. }
  16. for (int a=x-1; a>0;a-- )
  17. {
  18. if(a==x-1)
  19. System.out.print(a);
  20. else
  21. System.out.print(" "+a);
  22. }
  23. System.out.println();
  24. }
  25. }
  26. }
复制代码

评分

参与人数 1技术分 +1 收起 理由
夜默 + 1

查看全部评分

1 个回复

倒序浏览
占个沙发道个歉,新手第一次用代码粘贴,以为直接排版,不好意思哈大家。重新发代码。

  1. <P> </P>
复制代码
  1. class taxing
  2. {
  3.           public static void main(String[] args)
  4.           {
  5.                   int x,y,z;
  6.                  for(x=1;x<=4;x++)
  7.                  {
  8.                          for(y=7-x;y>=1;y--)
  9.                          {
  10.                                   System.out.print(" ");
  11.                          }
  12.                          for(z=1;z<=x;z++)
  13.                          {
  14.                                   System.out.print(z+" ");
  15.                           }
  16.                          for (int a=x-1; a>0;a-- )
  17.                          {
  18.                                    if(a==x-1)
  19.                                          System.out.print(a);
  20.                                    else
  21.                                          System.out.print(" "+a);
  22.                          }
  23.                          System.out.println();
  24.                  }
  25.          }
  26. }
复制代码
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马