打印多层圣诞树

 1     public static void main(String[] args)
 2     {
 3         for(int c=0;c<4;c++) //
 4         {
 5           for (int i = 1; i < 4; i++) 
 6           {
 7               for (int j = 4; j >= i; j--) 
 8               {
 9                   System.out.print(" ");
10               }
11               for (int k = 1; k <= 2 * i - 1; k++) 
12               {
13                   System.out.print("*");
14               }
15               System.out.println();
16           }
17         }
18      }        

打印结果如图所示:

猜你喜欢

转载自www.cnblogs.com/suyun0702/p/10813688.html