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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© pengjk 中级黑马   /  2016-1-11 22:25  /  1573 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

谁会输出菱形的星星?

   *
  ***
*****
*******
*****
  ***
   *
         

3 个回复

倒序浏览
  1. class PrintLingXing
  2. {
  3.         public static void main(String[] args)
  4.         {
  5.                 for(int x=0;x<5;x++)
  6.                 {
  7.                         for(int y=x;y<4;y++)
  8.                         {
  9.                                 System.out.print(" ");
  10.                         }
  11.                         for(int m=0;m<=x;m++)
  12.                         {
  13.                                 System.out.print("* ");
  14.                         }
  15.                         System.out.println();
  16.                 }
  17.                 for(int x=0;x<4;x++)
  18.                 {
  19.                         for(int y=0;y<=x;y++)
  20.                         {
  21.                                 System.out.print(" ");
  22.                         }
  23.                         for(int m=x;m<4;m++)
  24.                         {
  25.                                 System.out.print("* ");
  26.                         }
  27.                         System.out.println();
  28.                 }

  29.         }
  30. }
复制代码
回复 使用道具 举报
class practise3_lingxing {
        public static void main(String[] args) {
                for (int i = 0; i < 19; i++) {
        for (int j = 0; j < 19; j++) {
                if (j >= Math.abs(9 - i) && j < 19 - Math.abs(9 - i))
                        System.out.print("*");
                else
                        System.out.print(" ");
        }
        System.out.println();
                }
        }
}

//简单又好看,希望对你有帮助
回复 使用道具 举报
要定义两个for 循环
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马