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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© lshaizj 中级黑马   /  2015-5-3 10:47  /  722 人查看  /  18 人回复  /   1 人收藏 转载请遵从CC协议 禁止商业使用本文

                   1
                 1 2 1
               1 2 3 2 1
             1 2 3 4 3 2 1
           1 2 3 4 5 4 3 2 1
         1 2 3 4 5 6 5 4 3 2 1
       1 2 3 4 5 6 7 6 5 4 3 2 1
     1 2 3 4 5 6 7 8 7 6 5 4 3 2 1
   1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1
class SanJiao
{
        public static void main(String[] args)
        {
                int a=1;
                int b=0;
                int c=0;
                for (int x=1;x<=9 ;x++ )
                {
                        b=x;
                        for (int z=x;z<9 ; z++)
                        {
                                System.out.print(" ");
                        }
                        for (int y=1;y<=a ;y++ )
                        {
                                if (y<=x)
                                {
                                        System.out.print(y+" ");
                                }
                                else if (y>x)
                                {
                                        b--;
                                        System.out.print(b+" ");
                                }
                        }
                        a+=2;
                        c++;
                        System.out.println();
                }
        }
}

评分

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

查看全部评分

18 个回复

倒序浏览
good    code
回复 使用道具 举报
又是这种,我都不会
回复 使用道具 举报
学习下  嘿嘿
回复 使用道具 举报
这样的三角形就要用内层两个for循环的形式。
回复 使用道具 举报
这样的三角形就要用内层两个for循环的形式。
回复 使用道具 举报
yapo 中级黑马 2015-5-3 11:11:53
7#
不错额,多敲代码,慢慢地,你会成为黑马中的黑马
回复 使用道具 举报
如果将数字改为英文字母ABC。。。的话,会不会更好看点呢?

点评

这个只要输出的时候 System.out.print((char)(64+y));System.out.print((char)(64+b));就可以啦~~  发表于 2015-5-4 15:29
回复 使用道具 举报
数字字母都不好看,图形最好
回复 使用道具 举报
过来赞一个啦
回复 使用道具 举报
用到了多层的for循环,学习了
回复 使用道具 举报
不错,点赞
回复 使用道具 举报
学习下  
回复 使用道具 举报
本帖最后由 支离疏者 于 2015-5-4 14:36 编辑
  1. <blockquote>class NumTower
复制代码
回复 使用道具 举报
  1. class NumTower
  2. {
  3.         public static void main(String[] args)
  4.         {
  5.         numTower(5);
  6.         printhx();

  7.     }

  8. /*
  9. 输出
  10.     1
  11.    121
  12.   12321
  13. 1234321
  14. 123454321
  15. …………………………
  16. */
  17.         public static void numTower(int a)
  18.         {       
  19.                 for (int x=1;x<=a ;x++ )
  20.                 {
  21.                         for (int y=x; y<=a-1;y++ )
  22.                         {
  23.                                 System.out.print(" ");
  24.                         }
  25.                         for (int z=1;z<=x ; z++)
  26.                         {
  27.                                 System.out.print(z+" ");
  28.                                 if (z==x)
  29.                                 {
  30.                                         for (int ot=z-1;ot>0 ;ot-- )
  31.                                         {
  32.                                                 System.out.print(ot+" ");
  33.                                         }
  34.                                 }
  35.                         }
  36.                         System.out.println();
  37.                 }
  38.         }
  39.         public static void printhx()//定义打印分割线的功能
  40.         {
  41.                 System.out.println("-----------------");
  42.         }
  43. }
复制代码
回复 使用道具 举报
个人建议System.out.print(y+" ");和System.out.print(b+" ");不要叫空格,否则三角是变形的
回复 使用道具 举报
学习一下。
回复 使用道具 举报
学习学习。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马