黑马程序员技术交流社区

标题: 新手,写了个关于数字塔形的代码 [打印本页]

作者: breaveheart    时间: 2013-7-18 17:08
标题: 新手,写了个关于数字塔形的代码
看了毕老师关于输出星形形状的代码,自己参照写了个数字塔形的供大家看看。
新手可能有疏漏,有好想法的欢迎大家批评建议。{: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. }
复制代码

作者: breaveheart    时间: 2013-7-18 17:12
占个沙发道个歉,新手第一次用代码粘贴,以为直接排版,不好意思哈大家。重新发代码。

  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. }
复制代码





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2