/**
* 螺旋矩阵
*/
import java.io.*;
public class RingDemo {
public static void main(String args[]){
String strln = "";
System.out.println("请输入矩阵的行列数:");
InputStreamReader input = new InputStreamReader(System.in);
BufferedReader buff = new BufferedReader(input);
try{
strln = buff.readLine();
}catch(IOException e){
System.out.println(e.toString());
}
int int1 = Integer.parseInt(strln);
int n = int1;//读取的输入数
System.out.println("这是行列数为"+n+"的螺线型数组:");
int intA = 1;//初始化
int[][] array = new int[n][n];
int intB;//循环次数
if(n % 2 != 0){
intB = n / 2 + 1;
}else{
intB = n / 2;
}
for(int i = 0;i
//从左到右
for(int j = i;j
array[i][j] = intA;
intA++;
}
//从上到下
for(int k = i+1;k
array[k][n-i-1] = intA;
intA++;
}
//从右到左
for(int l = n-i-2;l >= i;l--){
array[n-i-1][l] = intA;
intA++;
}
//从下到上
for(int m = n-i-2;m >i;m--){
array[m][i] = intA;
intA++;
}
}
//输出数组
for(int i = 0; i
for(int j = 0; j
System.out.print(array[i][j]+" ");
}
System.out.println();
}
}
}