In java I need to create a recursive maze solver and it needs to read in a txt f
ID: 3692540 • Letter: I
Question
In java I need to create a recursive maze solver and it needs to read in a txt file that could look something like this
where the 6 indicates its a 6x6 maze and 1 are open paths, 3's are walls, 0 is the start, and 2 is the finish.
so far my code looks like
import java.util.Scanner;
import java.io.File;
public class mazesolver {
public static void main(String[] args)
{
try
{
File f = new File("in.txt");
Scanner input = new Scanner(f);
int rows = input.nextInt();
int col = rows;
int [][] maze = new int[rows][col];
String s = "";
//String start = "0";
//String end = "2";
//System.out.println(rows);
//System.out.println(col);
input.nextLine();
int r = 0;
while(input.hasNextLine())
{
s = input.nextLine();
//System.out.println(s);
//System.out.println(s.indexOf(start));
//System.out.println(s.indexOf(end));
for(int c = 0; c < col; c++)
{
maze[r][c] = Integer.parseInt(""+s.charAt(c));
System.out.println(maze[r][c]);
}
}
r++;
//System.out.println(s);
/*while(input.hasNextLine())
{
System.out.println(input.nextLine());
}*/
}
catch(Exception e)
{
e.printStackTrace();
}
}
Explanation / Answer
Your code seems good and fine but you need to trace your excaptions more peoperly for that youm can use logging (A Java logging framework is a computer data logging package for theJava platform. Logging refers to the recording of activity. Logging is a common issue for development teams. Several frameworks ease and standardize the process of logging for the Java platform.). An open source API named log4j can also be used for the same puropse. it is good
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.