用数组方法输出下列方阵:
 (1)n=4                   1   2   6   7
                            3   5   8   13
                            4   9   12  14
                            10  11  15  16  
         
      
(2)n=4                  1  2  5  10
                          4  3  6  11
                          9  8  7  12
                          16 15 14 13

解决方案 »

  1.   

    给你写了第一个,呵呵~~
    public class TestInners{
    public static void squareOutput(int num){
    int[][] intArray = new int[num][num];
    int value = 1;

    for(int i=0; i<=2*num-2; i++){
    for(int j=0; j<=i; j++){
    if(j < num && (i-j) < num){ 
    if(i%2 == 1) 
    intArray[j][i-j] = value++; 
    else 
    intArray[i-j][j] = value++;
    }
    }
    }

    for(int i=0; i<num; i++){
    for(int j=0; j<num; j++)
    System.out.print(intArray[i][j] +" ");

    System.out.println();
    }
    }

    public static void main(String[] args) throws Exception {
            squareOutput(4);
        } 
    }
      

  2.   

    晕 为啥我throws了一个exception啊?改一下啊 public static void main(String[] args){ //throws Exception {