黑马程序员技术交流社区

标题: 谁会输出菱形的星星? [打印本页]

作者: pengjk    时间: 2016-1-11 22:25
标题: 谁会输出菱形的星星?
谁会输出菱形的星星?

   *
  ***
*****
*******
*****
  ***
   *
         
作者: 黑色皮肤的马    时间: 2016-1-12 21:30
  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. }
复制代码

作者: wuzeshui    时间: 2016-1-12 21:49
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();
                }
        }
}

//简单又好看,希望对你有帮助
作者: n_Nie1991    时间: 2016-1-12 22:22
要定义两个for 循环




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