0
將字符串放入單個數組很容易,但我想將字符串放入2d char [] []; 我被困在這裏,可以有人幫助我...謝謝你,對不起我的英語不好!將字符串放入2維數組
String woord = "GPDNATSFASELNIERTPOTSRARIRRCOOFPUAUOGONOTORENOTUAMRHRILGTPOFRSCENOIEKLMETANTRSRUNIAARSETEITNAKAVERNTEJLIBFTNVOTWEEDEKLASC";
char[][] bord = new char[11][11];
char[] letters = woord.toCharArray();
int teller = 0;
//Board into a single array
for (int i = 0; i < woord.length(); i++) {
letters[i] = woord.charAt(i);
teller++;
System.out.print(letters[i]);
if (teller % 11 == 0) {
System.out.println();
}
}
//Board into a 2d Array
for (int r = 0; r < bord.length; r++) {
bord[r][0]=letters[r]; //<=== first 11 letters, next?
System.out.print(bord[r][0]);
for (int c = 0; c < bord[0].length; c++) {
//??
}
}
歡迎SO。請指出與您的問題相關的語言標籤。我已經爲你的問題添加了java。 –