矩阵2

来源:互联网 发布:vchat互动聊天室源码 编辑:程序博客网 时间:2024/06/11 18:32

这是另外一个数字游戏的逻辑算法,有了上一次的矩阵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;}}

运行效果如图:


0 0
原创粉丝点击