问题描述
我是编程和尝试找出如何将文件加载到2d数组中的新手。 该文件有几行。
第1行是测试用例行。 第2行是数组中的行和列数。还有使用左手规则还是右手规则。 第3行是开始位置和结束位置。
例如: 2 12 12升 2 1 11 12
我在测试用例中使用了T N代表行,M代表列,S代表开始,结束代表结束
import java.util.*;
public class lRMaze {
public static int [][] move = {
{0,1},{1,0},{0,-1},};
public static boolean east = true,north = false,south = false,west = false;
public static void main(String args[]) throws IOException {
// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
// Get the filename.
System.out.print("Enter the filename: ");
String filename = keyboard.nextLine();
// Open the file.
File file = new File(filename);
Scanner inputFile = new Scanner(file);
int T = inputFile.nextInt();
while (T !=0 || T < 20)
{
int N = inputFile.nextInt(); //number of rows in the maze
int M = inputFile.nextInt();// number of columns in the maze
String hand = inputFile.next(); // left-hand or right-hand
int sR = inputFile.nextInt(); // starting position row
int sC = inputFile.nextInt(); // starting position column
int fR = inputFile.nextInt(); // finish row
int fC = inputFile.nextInt(); // finish column
char [][] field = new char [N][M];
for (int i = 0; i <N; i++) {
String line = inputFile.next();
for (int j = 0; j < M; j++);{
field[i][j] = line.charAt(j);
}// end while
// Close the file.
我不知道我要怎么做。有人可以帮忙吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)