Java中的多维数组打印



我对Java编程有点陌生,我知道如何使用Java基本打印数组。但是,我目前需要的东西对我的关卡来说有点复杂。我搜索了一个帮助和例子没有帮助得到我想要的。

这是我需要的。

我需要输入以下内容:

int[][] array = { 
              {100, 12 , 0, 3},
              {100, 177, 0, 3},
              {100, 233, 0, 3}, 
              {100, 144242, 0, 3},
              {100, 14, 0, 4},  
              {100, 12234, 0, 4},
              {100, 134, 1, 4},
              {2, 15, 0, 3},
              {23, 1533, 0, 3},
              {23, 1322, 1, 4}, 
              {23, 13, 1, 4}, 
              {23, 122, 1, 4},
              {1321, 142, 1, 4},
              {1321, 133,1, 4},
              {3, 16, 0, 5},
              {55, 1003, 0,3},
              {553, 1002, 2, 6},
              {31, 162, 0, 5},
              {7, 1626, 0, 5},
              {7, 2336, 0,5}           
             };

我需要得到以下输出:

100 { 
    0{
       3{177,233,144242,12},
       4{14,12234}
    },
    1{
        3{}
        4{134}
    }
       ------------------
}

看这个。这会有帮助的。

public class Array {
public static void main(String[] args) {
    //pax(p) = Single, Double, Triple
    //p1=0 , p2=1, p3=2
    //basis(b) = RO, BB, HB, FB
    //b1=3 , b2=4 , b3=5 , b4=6
    int[][] array = { 
              {100, 12 , 0, 3},
              {100, 177, 0, 3},
              {100, 233, 0, 3}, 
              {100, 144242, 0, 3},
              {100, 14, 0, 4},  
              {100, 12234, 0, 4},
              {100, 134, 1, 4},
              {2, 15, 0, 3},
              {23, 1533, 0, 3},
              {23, 1322, 1, 4}, 
              {23, 13, 1, 4}, 
              {23, 122, 1, 4},
              {1321, 142, 1, 4},
              {1321, 133,1, 4},
              {3, 16, 0, 5},
              {55, 1003, 0,3},
              {553, 1002, 2, 6},
              {31, 162, 0, 5},
              {7, 1626, 0, 5},
              {7, 2336, 0,5}           
             };

    int riid = 0;
    int pax = 10;
    for (int i = 0; i < array.length; i++) {
        if (array[i][0] != riid) {
            riid = array[i][0];
            //System.out.print("n" + riid + "-" + array[i][1]);
        } else {
           // System.out.print("," + array[i][1]);
        }
        if (array[i][2] != pax) {
            pax = array[i][2];
            System.out.print("n" + riid + "-" + pax + "-" + array[i][1]);
       } else {
          System.out.print("," + array[i][1]);
       }
    }
}

}

相关内容

  • 没有找到相关文章

最新更新