代码如下:

 1 /*作者:***
 2  *日期:2016-03-01
 3  *功能:打印出镂空菱形
 4  */
 5 public class LouKongLingXing
 6 {
 7     public static void main(String []args)
 8     {
 9         int lay=6;
10         for(int i=1;i<=(lay*2-1);i++)
11         {
12             if(i<=lay)
13             {
14                 for(int j=1;j<=(lay-i);j++)
15                 {
16                     System.out.print(" ");
17                 }
18                 for(int j=1;j<=(2*i-1);j++)
19                 {
20                     if(j==1||j==(2*i-1))
21                     {
22                         System.out.print("*");
23                     }
24                     else
25                     {
26                         System.out.print(" ");
27                     }
28                 }
29             }else
30             {
31                 for(int j=1;j<=(i-lay);j++)
32                 {
33                     System.out.print(" ");
34                 }
35                 for(int j=1;j<=(4*lay-2*i-1);j++)
36                 {
37                     if(j==1||j==(4*lay-2*i-1))
38                     {
39                         System.out.print("*");
40                     }
41                     else
42                     {
43                         System.out.print(" ");
44                     }
45                 }
46             }
47             System.out.println("\n");
48         }
49     }
50 }

 

结果如下:

 

 1      *
 2 
 3     * *
 4 
 5    *   *
 6 
 7   *     *
 8 
 9  *       *
10 
11 *         *
12 
13  *       *
14 
15   *     *
16 
17    *   *
18 
19     * *
20 
21      *