1 public class TestFor19{ 2 public static void main(String [] args){ 3 int size =32; 4 int startNum=size/2+1; 5 int endNum=size/2+1; 6 boolean flag = true; 7 for(int j=1;j<=size;j++){ 8 for(int i=1;i<=size;i++){ 9 if(i==startNum||i==endNum){//前面为空心菱形,//i>=startNum&&i<=endNum实心菱形 10 System.out.print("*"); 11 }else{ 12 System.out.print(" "); 13 } 14 15 } 16 System.out.println(); 17 if(endNum==size){ 18 flag=false; 19 } 20 if(flag){//flag是true相当于在菱形的上班层 21 startNum--; 22 endNum++; 23 }else{ 24 startNum++; 25 endNum--; 26 } 27 28 } 29 30 } 31 32 }