菱形的循环
public class PrintDemo {
public static void main(String[] args) {
int n=7;
int m=n/2;
int begin=m;
int end=m;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(j>=begin && j<=end){
System.out.print("* ");
}else{
System.out.print(" ");
}
}
System.out.println();
if(i<m){
begin--;
end++;
}else{
begin++;
end--;
}
}
}
} |