本人对输出图案之类的很薄弱,弄了很久都没把下面的这个图案输出,希望大家帮帮忙
1  3   6  10  15
2  5   9  14
4  8  13
7  12
11

解决方案 »

  1.   

    /*
     1 3 6 10 15
     2 5 9 14
     4 8 13
     7 12
     11
     */
    public class Test {
        public static void main(String[] args) {
            int[][] ns = new int[5][5];
            int sn = 1;
            for (int row = 0; row < ns.length; ++row) {
                int i = row;
                int j = 0;            // 从第N行向右上角走,走不通,则进行下一行
                do {
                    ns[i][j] = sn++;
                    --i;
                    ++j;
                } while (i >= 0 && j < ns[0].length);
            }        for (int i = 0; i < ns.length; ++i) {
                for (int j = 0; j < ns[0].length; ++j) {
                    System.out.printf("%-3s", ns[i][j] != 0 ? ns[i][j] : "");
                }
                System.out.println();
            }
        }
    }
      

  2.   

    public class TestB { /**
     * @param args
     */
    public static void main(String[] args) {
    int[][] a=new int[5][5];

      int m=1;
      int p=0;
    for(int i=0;i<5;i++){
    p=i;
    for(int j=1;j<=5;j++){
    if(p>=0){
    a[p][j-1]=m;
    m++;
    }
    p--;
    }}
    int k=5;
       for(int i=0;i<5;i++){
       
      for(int j=0;j<k;j++){
      System.out.print("  "+a[i][j]);
      
      } 
       k--;
       System.out.println();
       }
    }}