[英]How to take two different string array elements as input to one 2D array in java
[英]How to input a string one charecter at a time into a 2d array
所以我有一個字符串,我需要將其放入2d數組中,這是我到目前為止所擁有的。
mazeString = ".............."
char[][] mazeArray = new char [50][30];
for (int i = 0; i < (height*2)-1; i++){
for (int j = 0; j < (width*2)-1; j++){
mazeArray[j][i] = mazeString.next();
}
}
如評論中所述, mazeString
被聲明並初始化為String Literal。 所有.next()
方法都保留用於Scanner對象。 Java不允許您使用掃描
所以我想通了。
while (input.hasNextLine()) {
mazefile = mazefile + input.nextLine();
}
for (int i = 0; i < (height*2)+1; i++){
for (int j = 0; j < (width*2)+1; j++){
mazeArray[i][j] = mazefile.charAt(counter);
counter++;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.