public class Hellojava{ static final int rows=79; public static void main(String []arge) { int row; for(row=1;row<rows/2+1;row++) { for(int i=1;i<=(rows-2*row-1)/2;i++) System.out.print(" "); for(int j=0;j<2*row-1;j++) System.out.print("*"); System.out.print("\n"); } for(row-=2;row>=1;row--) { for(int i=1;i<=(rows-2*row-1)/2;i++) System.out.print(" "); for(int j=0;j<2*row-1;j++) System.out.print("*"); System.out.print("\n"); } } }
总行数rows 行数row 和 “*”数有关系 number=2row+1;和“ ”有关系number=(rows-2row-1)/2