package com.geminno.he0126;
public class Test08 {
public static void main(String[] args) {
int size = 5;
int centerNum = (size/2)+1;
int startNum = centerNum;
int endNum = centerNum;
boolean more = true; //#号增多的方向
for(int a=1;a<=size;a++){
for(int i=1;i<=size;i++){
if(i>=startNum&&i<=endNum){
System.out.print("* ");
}else{
System.out.print(" ");
}
}
System.out.println();
if(more){
startNum -= 1;
endNum += 1;
}else{
startNum += 1;
endNum -= 1;
}
if(startNum==1){
more = false;
}
}
}
}
转载于:https://my.oschina.net/YongfengHe/blog/633051