写个程序,打印出以下数据:
 1   2   6   7  15  16  28  29  45  
 3   5   8  14  17  27  30  44  46  
 4   9  13  18  26  31  43  47  60  
10  12  19  25  32  42  48  59  61  
11  20  24  33  41  49  58  62  71  
21  23  34  40  50  57  63  70  72  
22  35  39  51  56  64  69  73  78  
36  38  52  55  65  68  74  77  79  
37  53  54  66  67  75  76  80  81  

解决方案 »

  1.   


    刚刚在网上看见的。public class Test { /**
     * <pre>
     * 方法名称:
     * 功能描述:
     * &#064;param args
     * void
     * </pre>
     */
    public static void main(String[] args) {
    printPoint(9);
    } public static void printPoint(int num) { Integer[][] a = new Integer[num][num]; int start = 1; for (int i = 0; i < num; i++) { for (int k = 0; k <= i; k++) {
    if (i % 2 == 0) {
    a[i - k][k] = start++;
    } else {
    a[k][i - k] = start++;
    }
    }
    }
    int end = num * num;
    for (int f = num * 2 - 2; f >= num; f--) { for (int m = num - 1; m > f - num; m--) { if (f % 2 == 0) {
    a[f - m][m] = end--;
    } else {
    a[m][f - m] = end--;
    } }
    }
    for (int x = 0; x < a[0].length; x++) { for (int y = 0; y < a[0].length; y++) {
    String str = a[x][y].toString();
    if (a[x][y].toString().length() < 2) {
    str = " " + str;
    }
    System.out.print(str + "  ");
    }
    System.out.println();
    } }}