簡體   English   中英

返回int [] []數組

[英]Return int[][] array

這可能是一個荒謬的問題,但我沒有做到。 我有兩個此類型的數組:

String[] string{"A", "B", "C"}int[][] array {{1, 2, 3},{1, 2, 3}}

並希望獲得以下輸出:

1 1

B 2 2

C 3 3

我幾乎嘗試了所有可能的for循環,但順序不盡相同。 非常感謝您的幫助!

嘗試這個:

// INIT ARRAYS
String[] abcArray = {"A", "B", "C"};
int[][] otherArray = {{1, 2, 3},{1, 2, 3}};

// LOOP ABC ARRAY
for(int x = 0; x < abcArray.length; x++){

    // PRINT
    system.out.println(abcArray[x]+otherArray[0][x]+otherArray[1][x]);

}
    String[] string = {"A", "B", "C"};
    int[][] array = {{1, 2, 3},{1, 2, 3}};

    for (int i = 0; i < string.length; i++) {
        System.out.print(string[i]);
        for (int j = 0; j < array.length; j++) {
            System.out.print(" " + array[j][i]);
        }
        System.out.println();
    }

只要您的字符串數組與2d數組中的每個int數組具有相同的長度,這將產生所需的輸出。 您可以根據用例調整for循環,但是您會明白的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM