这是另外一个数字游戏的逻辑算法,有了上一次的矩阵1,这种类型的题目做起来得心应手啊!
public class Test5 {
/*
1
5 2
8 6 3
10 9 7 4
分析:
arr[1][0] arr[3][3]
arr[2][0] arr[3][2]
*/
public static void main(String[] args) {
Test5 t=new Test5();
Test4 t2=new Test4(); //输出
t2.printData(t.test(10));
}
public int[][] test(int n){
int arr[][]=new int[n][n];
for (int i = 0; i < n; i++) { //控制次数
for (int j = 0,c=i;j<n&&c<n; j++,c++) { //一次循环打印的列数
if(c==i){
if(c==0)
arr[c][j]=1;
else
arr[c][0]=arr[n-1][n-c]+1;
}
else{
arr[c][j]=arr[c-1][j-1]+1;
}
}
}
return arr;
}
}
运行效果如图: