[英]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.