第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

用Java初始化多維數(shù)組

用Java初始化多維數(shù)組

慕無忌1623718 2019-07-10 16:39:57
用Java初始化多維數(shù)組聲明多維數(shù)組并為其賦值的正確方法是什么?這就是我所擁有的:int x = 5;int y = 5;String[][] myStringArray = new String [x][y];myStringArray[0][x] = "a string";myStringArray[0][y] = "another string";
查看完整描述

3 回答

?
至尊寶的傳說

TA貢獻(xiàn)1789條經(jīng)驗(yàn) 獲得超10個(gè)贊

Java沒有“真”多維數(shù)組。

例如,arr[i][j][k]等于((arr[i])[j])[k]..換句話說,arr是簡(jiǎn)單的數(shù)組、數(shù)組的數(shù)組.

所以,如果您知道數(shù)組是如何工作的,那么您就知道多維數(shù)組是如何工作的!


聲明:

int[][][] threeDimArr = new int[4][5][6];

或者,在初始化時(shí):

int[][][] threeDimArr = { { { 1, 2 }, { 3, 4 } }, { { 5, 6 }, { 7, 8 } } };

準(zhǔn)入:

int x = threeDimArr[1][0][1];

int[][] row = threeDimArr[1];

字符串表示:

Arrays.deepToString(threeDimArr);

產(chǎn)量

"[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]"


查看完整回答
反對(duì) 回復(fù) 2019-07-10
?
海綿寶寶撒

TA貢獻(xiàn)1809條經(jīng)驗(yàn) 獲得超8個(gè)贊

您可以聲明多維數(shù)組如下:


// 4 x 5 String arrays, all Strings are null

// [0] -> [null,null,null,null,null]

// [1] -> [null,null,null,null,null]

// [2] -> [null,null,null,null,null]

// [3] -> [null,null,null,null,null]


String[][] sa1 = new String[4][5];

for(int i = 0; i < sa1.length; i++) {           // sa1.length == 4

    for (int j = 0; j < sa1[i].length; j++) {     //sa1[i].length == 5

        sa1[i][j] = "new String value";

    }

}



// 5 x 0  All String arrays are null

// [null]

// [null]

// [null]

// [null]

// [null]

String[][] sa2 = new String[5][];

for(int i = 0; i < sa2.length; i++) {

    String[] anon = new String[ /* your number here */];

    // or String[] anon = new String[]{"I'm", "a", "new", "array"};

    sa2[i] = anon;

}


// [0] -> ["I'm","in","the", "0th", "array"]

// [1] -> ["I'm", "in", "another"]

String[][] sa3 = new String[][]{ {"I'm","in","the", "0th", "array"},{"I'm", "in", "another"}};



查看完整回答
反對(duì) 回復(fù) 2019-07-10
  • 3 回答
  • 0 關(guān)注
  • 970 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)