19 打印菱形图案

题目: 打印出如下图案(菱形)

     *
   ***
 *****
*******
 *****
   ***
    *

 1     public class _019PrintDiamond {
 2 
 3     public static void main(String[] args) {
 4         printDiamond();
 5     }
 6 
 7     private static void printDiamond() {
 8         int hight = 7, width = 7;
 9         
10         //打印上三角
11         for(int i =0;i<(hight+1)/2;i++){
12             //行循环
13             for(int j =0;j<width/2-i;j++){
14                 //循环图形中的空格数量
15                 System.out.print(" ");
16             }
17             
18             //列循环
19             for (int s=1;s<(i+1)*2;s++) {
20                 System.out.print('*');
21             }
22             System.out.println();
23         }
24         
25         //打印下三角
26         for(int i =1;i<=hight/2;i++){
27             for(int j =1;j<=i;j++){
28                 System.out.print(" ");
29             }
30             
31             for (int s=1;s<=width-2*i;s++) {
32                 System.out.print('*');
33             }
34             System.out.println();
35         }
36     }
37 }
原文地址:https://www.cnblogs.com/liuyangfirst/p/6514639.html