class SpinTest {
public static void main(String[] args) {
int i = 0;
int j = 0;
int k = 0;
int n = 5;
int[][] arr=new int[n][n];
int s = 0;
for ( i=0; i<=n-1-k; i++){
for ( j=i; j<n-1-k; j++){
arr[i][j]=++s;
}
for ( ; i<n-1-k; i++){
arr[i][j]=++s;
}
for ( ; j>k; j--){
arr[i][j]=++s;
}
for ( ; i>k; i--){
arr[i][j]=++s;
}
if(i==(n-1)/2){ //(n-1)/2 改成j 为什么不行
arr[i][j]=++s;
};
k++;
}
for ( i=0; i<n; i++){
for ( j=0; j<n; j++){
System.out.print(arr[i][j]+"\t");
}
System.out.println(" ");
}
}
} |
|