1 2 6 7
3 5 8 13
4 9 12 14
10 11 15 16
1 2 5 10
4 3 6 11
9 8 7 12
16 15 14 13
您这问题没法会打 最简单就是 四个数一换行 \n 打印就行了 不会想要这样吧
class ASD
{
public static void main(String[]args)
{
int[]a={1,2,6,7,3,5,8,13,4,9,12,14,10,11,15,16,1,2,5,10,4,3,6,11,9,8,7,12,16,15,14,13};
int n=0;
for(int i=0;i<=a.length-1;i++)
{
System.out.print(a[i]+" ");
n++;
if(n%4==0)
{
System.out.println();
}
}
}
}
public static void run(int n){
int arr[][]=new int[n][n];
int args[][]=new int[(n<<1)-1][];
int count=1;
for(int i=0;i<(n<<1)-1;i++){
args[i]=new int[i>=n?(n<<1)-i-1:i+1];
int j=0;
if((i&1)==0){
while(j
}
}else{
while(j++
}
}
}
for(int i=0;i
}
}
for(int[] a:arr){
System.out.println(Arrays.toString(a));
}
}
参数为8的结果:
[1, 2, 6, 7, 15, 16, 28, 29]
[3, 5, 8, 14, 17, 27, 30, 43]
[4, 9, 13, 18, 26, 31, 42, 44]
[10, 12, 19, 25, 32, 41, 45, 54]
[11, 20, 24, 33, 40, 46, 53, 55]
[21, 23, 34, 39, 47, 52, 56, 61]
[22, 35, 38, 48, 51, 57, 60, 62]
[36, 37, 49, 50, 58, 59, 63, 64]
想了半天 还是没思路 算了
麻烦把方阵打出来