输出空心菱形

 1 //输出空心菱形,利用输出实心菱形的算法
 2         
 3         //输出上半部分
 4         
 5         for(int hs= 0;hs<=9;hs++)
 6         {
 7             //输出空格
 8             for(int kg=8;kg>=hs;kg--)
 9             {
10                 System.out.print(" ");
11             }
12             
13             //输出第一个点
14             System.out.print("*");
15             
16             if(hs==0)
17             {
18             }
19             else
20             {
21                 //输出中心的空格
22                 for(int ds=1;ds<=2*hs-1;ds++)
23                 {
24                     System.out.print(" ");
25                 }
26                 //输出第二个点
27                 System.out.print("*");
28             }
29             System.out.println();
30         }
31         
32         //输出下半部分
33         
34         for(int hs= 8;hs>=0;hs--)
35         {
36             //输出空格
37             for(int kg=8;kg>=hs;kg--)
38             {
39                 System.out.print(" ");
40             }
41             
42             //输出第一个点
43             System.out.print("*");
44             
45             if(hs==0)
46             {
47             }
48             else
49             {
50                 //输出中心的空格
51                 for(int ds=1;ds<=2*hs-1;ds++)
52                 {
53                     System.out.print(" ");
54                 }
55                 //输出第二个点
56                 System.out.print("*");
57             }
58             System.out.println();
59         }

利用和输出实心菱形同样的算法!

原文地址:https://www.cnblogs.com/zhengfengyun/p/5112076.html