黑马程序员技术交流社区

标题: 关于for 打印各种 星星图形(比较简单就没写注释) [打印本页]

作者: 吃肉的小绵羊    时间: 2016-3-23 19:21
标题: 关于for 打印各种 星星图形(比较简单就没写注释)
*****
*****
*****
*****
  1. class  TuXing1
  2. {
  3.         public static void main(String[] args)
  4.         {
  5.               for(int x=0;x <5 ;x++ )
  6.               {
  7.                           for(int y=0;y<5;y++)
  8.                           {
  9.                              System.out.print("* ");
  10.                           
  11.                           }
  12.           System.out.println(" ");
  13.               }

  14.     }
  15. }
复制代码

*
**
***
****
*****
  1. lass TuXing2
  2. {
  3.         public static void main(String[] args)
  4.         {
  5.                 for(int x=0;x<=5;x++)
  6.                 {
  7.                         for(int y=0;y<x;y++)
  8.                         {
  9.                          System.out.print("*");
  10.                         }
  11.                         System.out.println(" ");
  12.                 }
  13.         }
  14. }
复制代码

******
*****
****
***
**
*
  1. class TuXing3
  2. {
  3.         public static void main(String[] args)
  4.         {
  5.                 for(int x=0;x<=5;x++)
  6.                 {
  7.                         for(int y=x;y<=5;y++)
  8.                         {
  9.                          System.out.print("*");
  10.                         }
  11.                         System.out.println(" ");
  12.                 }
  13.         }
  14. }
复制代码

    *
   **
  ***
****
*****
  1. class TuXing4
  2. {
  3.         public static void main(String[] args)
  4.         {
  5.                 for(int x=1;x<=5;x++)
  6.                 {
  7.                         for(int y=1;y<=5-x;y++)
  8.                         {
  9.                          System.out.print(" ");
  10.                         }
  11.                          for(int z=1;z<=x;z++)
  12.                         {
  13.                                  
  14.                                  System.out.print("*");
  15.                         }
  16.                        
  17.                        
  18.                         System.out.println(" ");
  19.                 }
  20.         }
  21. }

复制代码

*****
****
  ***
   **
    *
  1. class TuXing5
  2. {
  3.         public static void main(String[] args)
  4.         {
  5.                 for(int x=1;x<=5;x++)
  6.                 {
  7.                         for(int y=0;y<x-1;y++)
  8.                         {
  9.                          System.out.print(" ");
  10.                         }
  11.                          for(int z=0;z<6-x;z++)
  12.                         {
  13.                                  
  14.                                  System.out.print("*");
  15.                         }
  16.                        
  17.                        
  18.                         System.out.println(" ");
  19.                 }
  20.         }
  21. }

复制代码

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

*******
*****
  ***
   *
  1. class TuXing7
  2. {
  3.         public static void main(String[] args)
  4.         {
  5.                 for(int x=0;x<5;x++)
  6.                 {
  7.                         for(int y=0;y<x;y++)
  8.                         {
  9.                          System.out.print(" ");
  10.                         }
  11.                          for(int z=0;z<7-2*x;z++)
  12.                         {
  13.                                  
  14.                          System.out.print("*");
  15.                         }
  16.                        
  17.                        
  18.                         System.out.println(" ");
  19.                 }
  20.         }
  21. }

复制代码

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

复制代码

   ******
  ******
******
******
  1. class TuXing9
  2. {
  3.         public static void main(String[] args)
  4.         {
  5.                 for(int x=0;x<4;x++)
  6.                 {
  7.            for(int y=0;y<4-x;y++)
  8.                          {
  9.                           System.out.print(" ");
  10.                      }
  11.                    for(int z=0;z<6;z++)
  12.                          {
  13.                           System.out.print("*");
  14.                   
  15.                      }
  16.                          System.out.println(" ");
  17.                 }
  18.         }
  19. }
复制代码

    *****
   *******
  *********
***********
*************
  1. class TuXing10
  2. {
  3.         public static void main(String[] args)
  4.         {
  5.           for(int x=0;x<5;x++)
  6.                 {
  7.               for(int y=0;y<4-x;y++)  
  8.                    {
  9.                       System.out.print(" ");
  10.                     }
  11.                         for(int z=0;z<5+2*x;z++)
  12.                         {
  13.                             System.out.print("*");
  14.                          }
  15.                          System.out.println(" ");
  16.             }
  17.         }
  18. }
复制代码

作者: Yoyoqiu    时间: 2016-3-23 20:09
刚好看到九九乘法表   谢谢楼主了
作者: kaifei2018    时间: 2016-3-23 21:19
黑马程序员入驻传智郑州校区

吃住行全览,UI设计学科首期开设!
作者: 追梦de蜗牛2016    时间: 2016-3-23 22:22
顶一下,不错!
作者: 吃肉的小绵羊    时间: 2016-3-24 16:21
Yoyoqiu 发表于 2016-3-23 20:09
刚好看到九九乘法表   谢谢楼主了

加油
作者: youngsave    时间: 2016-3-24 16:54
哈哈这个好
作者: 丿若恋灬如初    时间: 2016-3-24 17:07
for循环应用,值得学习




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