1 /**
2 * This program would print out a diamond
3 * @param row the row of diamond
4 * @version 2018-7-23
5 * @author Lei
6 */
7 import java.util.*;
8
9 class LingXingDemo1
10 {
11 public static void main(String[] args)
12 {
13 System.out.println("please input row:(e.g.3、5、7、9、11...)");
14 Scanner in = new Scanner(System.in);
15 int row = in.nextInt();
16
17 for(int i=1;i<=row;i++){//控制总行数
18 if(i<=(row/2 +1)){//菱形上半部分
19 for(int j=1;j<=(row/2 + 1 - i); j++){//每行中的空格
20 System.out.print(" ");
21 }
22 for(int k=1;k<=2*i-1;k++){//每行中的*号
23 System.out.print("*");
24 }
25 System.out.println();//换行
26 }else{//菱形下半部分
27 for(int j=1;j<=(i-(row/2+1));j++){//每行中的空格
28 System.out.print(" ");
29 }
30 for(int k=1;k<=(2*(row-i)+1);k++){
31 System.out.print("*");//每行中的*号
32 }
33 System.out.println();//换行
34 }
35 }
36 }
37 }
please input row:(e.g.3、5、7、9、11...)
11
*
***
*****
*******
*********
***********
*********
*******
*****
***
*
请按任意键继续. . .