醉生梦死
夜半钟声到客船 Always Alone..

今天在群里聊天的时候看到这么一道笔试题,题目大意如下

 

编程实现

1

5  2

8  6  3

10  9  7  4

 

本人写的代码如下:

  @Test
    public void test2() {
        int num = 1;
        //定义行数
        final int scope = 6;
        int[][] Array = new int[scope][scope];

        for (int i = 0; i < scope; i++) {
            int temp = scope;
            Array[i][i] = num++;
            for (int j = i + 1; j < scope; j++) {
                Array[j][i] = Array[j - 1][i] + temp--;
            }
        }

        for (int i = 0; i < scope; i++) {
            for (int j = 0; j < i + 1; j++) {
                System.out.print(Array[i][j] + " ");
            }
            System.out.println();
        }
    }

 

posted on 2014-09-09 21:30  60℃.咖啡  阅读(174)  评论(0)    收藏  举报