SlideShare a Scribd company logo
1 of 3
Please copy and paste the code and explain why it won't work. It is supposed to take a maze and
return the exits and number of exits.
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
public class MazeSolver
{
int numRows;
int numCols;
int startRow;
int startCol;
int rows;
int col;
public static void loadMaze(){
int numRows;
int numCols;
int startRow;
int startCol;
int rows;
int col;
try{
Scanner input = new Scanner(System.in);
System.out.println("Please enter file name:");
String filename = input.nextLine();
File file = new File(filename);
Scanner fileInput = new Scanner(file);
numRows = fileInput.nextInt();
numCols = fileInput.nextInt();
ArrayList column= new ArrayList<String>();
ArrayList row = new ArrayList<String>();
char[][] maze= new char[numRows][numCols];
//for the row, get array start row and column index
for (int i = 0; i < numRows; i++) {
String line = fileInput.next();
for (int j = 0; j < numCols; j++) {
char empt = ' ';
maze[i][j] =
if (maze[i][j] == empt){
startRow = i;
startCol = j;
System.out.println(i);
//solveMaze(maze[i][j]);
}
else{
return;
}
}
}
fileInput.close();
}
catch(FileNotFoundException e) {
System.out.println("File not found.");
loadMaze();
}
}
// Method to solve the maze
public void solveMaze(char[][] maze) {
ArrayList<Integer> exitRows = new ArrayList<Integer>();
ArrayList<Integer> exitCols = new ArrayList<Integer>();
boolean[][] visited = new boolean[numRows][numCols];
// Call recursive method to explore the maze
exploreMaze(startRow, startCol, visited, maze, exitRows, exitCols);
// Print number of exits found
System.out.println("Number of exits found: " + exitRows.size());
// Print positions of exits
for (int i = 0; i < exitRows.size(); i++) {
System.out.println("Exit found at: (" + exitRows.get(i) + ", " + exitCols.get(i) + ")");
}
}
public void exploreMaze(int row, int col, boolean[][] visited, char[][] maze, ArrayList<Integer>
exitRows, ArrayList<Integer> exitCols) { // Recursive method to explore the maze
if (row < 0 || col < 0 || row >= numRows || col >= numCols || visited[row][col]) { // Base case: if
current position is out of bounds or already visited
return;
}
// Base case: if current position is an exit
if (maze[row][col] == 'E'){
exitRows.add(row);
exitCols.add(col);
return;
}
// Mark current position as visited
visited[row][col] = true;
exploreMaze(row-1, col, visited, maze,exitRows, exitCols); // up
exploreMaze(row, col+1, visited, maze,exitRows, exitCols); // right
exploreMaze(row+1, col, visited, maze,exitRows, exitCols); // down
exploreMaze(row, col-1, visited, maze,exitRows, exitCols); // left
// Recursively explore neighboring positions
}
}

More Related Content

Similar to Please copy and paste the code and explain why it won't work- It is su.docx

Java Question Consider a maze made up of a rectangular array of squ.pdf
Java Question Consider a maze made up of a rectangular array of squ.pdfJava Question Consider a maze made up of a rectangular array of squ.pdf
Java Question Consider a maze made up of a rectangular array of squ.pdf
wasemanivytreenrco51
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
fantasiatheoutofthef
 
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerKOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
Aiman Hud
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
Codecamp Romania
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
akkhan101
 
C++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfC++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdf
Rahul04August
 
Example of JAVA Program
Example of JAVA ProgramExample of JAVA Program
Example of JAVA Program
Trenton Asbury
 
Using Arrays with Sorting and Searching Algorithms1) This program .pdf
Using Arrays with Sorting and Searching Algorithms1) This program .pdfUsing Arrays with Sorting and Searching Algorithms1) This program .pdf
Using Arrays with Sorting and Searching Algorithms1) This program .pdf
f3apparelsonline
 
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 Problem1 java codeimport java.util.Scanner; Java code to pr.pdf Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
anupamfootwear
 

Similar to Please copy and paste the code and explain why it won't work- It is su.docx (20)

Java Question Consider a maze made up of a rectangular array of squ.pdf
Java Question Consider a maze made up of a rectangular array of squ.pdfJava Question Consider a maze made up of a rectangular array of squ.pdf
Java Question Consider a maze made up of a rectangular array of squ.pdf
 
MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdfMagicSquareTest.java import java.util.Scanner;public class Mag.pdf
MagicSquareTest.java import java.util.Scanner;public class Mag.pdf
 
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
Øredev 2011 - JVM JIT for Dummies (What the JVM Does With Your Bytecode When ...
 
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
 
Huraira_waris_Assgnment_4.docx
Huraira_waris_Assgnment_4.docxHuraira_waris_Assgnment_4.docx
Huraira_waris_Assgnment_4.docx
 
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerKOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
KOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
 
C++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfC++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdf
 
131 Lab slides (all in one)
131 Lab slides (all in one)131 Lab slides (all in one)
131 Lab slides (all in one)
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
 
What is new in Java 8
What is new in Java 8What is new in Java 8
What is new in Java 8
 
Example of JAVA Program
Example of JAVA ProgramExample of JAVA Program
Example of JAVA Program
 
10. Recursion
10. Recursion10. Recursion
10. Recursion
 
Test code
Test codeTest code
Test code
 
Using Arrays with Sorting and Searching Algorithms1) This program .pdf
Using Arrays with Sorting and Searching Algorithms1) This program .pdfUsing Arrays with Sorting and Searching Algorithms1) This program .pdf
Using Arrays with Sorting and Searching Algorithms1) This program .pdf
 
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 Problem1 java codeimport java.util.Scanner; Java code to pr.pdf Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 
CODEimport java.util.; public class test { public static voi.pdf
CODEimport java.util.; public class test { public static voi.pdfCODEimport java.util.; public class test { public static voi.pdf
CODEimport java.util.; public class test { public static voi.pdf
 
Tips and Tricks of Developing .NET Application
Tips and Tricks of Developing .NET ApplicationTips and Tricks of Developing .NET Application
Tips and Tricks of Developing .NET Application
 

More from cgraciela1

Please complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxPlease complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docx
cgraciela1
 
Please code in C language- Please do part 1 and 2- Do not recycle answ.docx
Please code in C language- Please do part 1 and 2- Do not recycle answ.docxPlease code in C language- Please do part 1 and 2- Do not recycle answ.docx
Please code in C language- Please do part 1 and 2- Do not recycle answ.docx
cgraciela1
 
Please answer the 3 questions- Case Study 2 Too Much Fatigue and Stres.docx
Please answer the 3 questions- Case Study 2 Too Much Fatigue and Stres.docxPlease answer the 3 questions- Case Study 2 Too Much Fatigue and Stres.docx
Please answer the 3 questions- Case Study 2 Too Much Fatigue and Stres.docx
cgraciela1
 
Please answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docxPlease answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docx
cgraciela1
 

More from cgraciela1 (20)

PLEASE HELP The above table shows the annual incomes of individuals.docx
PLEASE HELP   The above table shows the annual incomes of individuals.docxPLEASE HELP   The above table shows the annual incomes of individuals.docx
PLEASE HELP The above table shows the annual incomes of individuals.docx
 
Please give examples on all of the following titles and solve them as.docx
Please give examples on all of the following titles and solve them as.docxPlease give examples on all of the following titles and solve them as.docx
Please give examples on all of the following titles and solve them as.docx
 
please give the answer please give the answer A product's life cycl.docx
please give the answer please give the answer    A product's life cycl.docxplease give the answer please give the answer    A product's life cycl.docx
please give the answer please give the answer A product's life cycl.docx
 
please give a details explanation- i tried but i keep getting erronou.docx
please give a details explanation-  i tried but i keep getting erronou.docxplease give a details explanation-  i tried but i keep getting erronou.docx
please give a details explanation- i tried but i keep getting erronou.docx
 
Please explain- Thank you! 3- Show intermediate steps of sorting the a.docx
Please explain- Thank you! 3- Show intermediate steps of sorting the a.docxPlease explain- Thank you! 3- Show intermediate steps of sorting the a.docx
Please explain- Thank you! 3- Show intermediate steps of sorting the a.docx
 
Please explain why the answer is B instead of D 5- Which of the follow.docx
Please explain why the answer is B instead of D 5- Which of the follow.docxPlease explain why the answer is B instead of D 5- Which of the follow.docx
Please explain why the answer is B instead of D 5- Which of the follow.docx
 
Please Drawing this numbers using python Draw these follow.docx
Please Drawing this numbers using python             Draw these follow.docxPlease Drawing this numbers using python             Draw these follow.docx
Please Drawing this numbers using python Draw these follow.docx
 
PLEASE don't copy and paste from a previous answer because it was inco.docx
PLEASE don't copy and paste from a previous answer because it was inco.docxPLEASE don't copy and paste from a previous answer because it was inco.docx
PLEASE don't copy and paste from a previous answer because it was inco.docx
 
Please draw concept map Cdc45 Cdc6 Cdt1 Clamp Clamp loader CMG comp.docx
Please draw concept map    Cdc45 Cdc6 Cdt1 Clamp Clamp loader CMG comp.docxPlease draw concept map    Cdc45 Cdc6 Cdt1 Clamp Clamp loader CMG comp.docx
Please draw concept map Cdc45 Cdc6 Cdt1 Clamp Clamp loader CMG comp.docx
 
Please dont copy paste a-What is customer service- b- Main theories o.docx
Please dont copy paste a-What is customer service-  b- Main theories o.docxPlease dont copy paste a-What is customer service-  b- Main theories o.docx
Please dont copy paste a-What is customer service- b- Main theories o.docx
 
PLEASE DONT COPY ANSWER Draw a DFA that accepts the strings that repre.docx
PLEASE DONT COPY ANSWER Draw a DFA that accepts the strings that repre.docxPLEASE DONT COPY ANSWER Draw a DFA that accepts the strings that repre.docx
PLEASE DONT COPY ANSWER Draw a DFA that accepts the strings that repre.docx
 
Please do this for me!! I would gladly appreciate it- Write one result.docx
Please do this for me!! I would gladly appreciate it- Write one result.docxPlease do this for me!! I would gladly appreciate it- Write one result.docx
Please do this for me!! I would gladly appreciate it- Write one result.docx
 
Please complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxPlease complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docx
 
Please code in C language- Please do part 1 and 2- Do not recycle answ.docx
Please code in C language- Please do part 1 and 2- Do not recycle answ.docxPlease code in C language- Please do part 1 and 2- Do not recycle answ.docx
Please code in C language- Please do part 1 and 2- Do not recycle answ.docx
 
please ask and answer questions in internet technologies in the follo.docx
please ask and answer questions in  internet technologies in the follo.docxplease ask and answer questions in  internet technologies in the follo.docx
please ask and answer questions in internet technologies in the follo.docx
 
Please answer the multiple choice questions with detailed explanation.docx
Please answer the multiple choice questions with detailed explanation.docxPlease answer the multiple choice questions with detailed explanation.docx
Please answer the multiple choice questions with detailed explanation.docx
 
Please answer the following questions about the network of streets in.docx
Please answer the following questions about the network of streets in.docxPlease answer the following questions about the network of streets in.docx
Please answer the following questions about the network of streets in.docx
 
Please answer 16-29- thank you P4- Dissection of the Fetal Pig Ventr.docx
Please answer 16-29- thank you   P4- Dissection of the Fetal Pig Ventr.docxPlease answer 16-29- thank you   P4- Dissection of the Fetal Pig Ventr.docx
Please answer 16-29- thank you P4- Dissection of the Fetal Pig Ventr.docx
 
Please answer the 3 questions- Case Study 2 Too Much Fatigue and Stres.docx
Please answer the 3 questions- Case Study 2 Too Much Fatigue and Stres.docxPlease answer the 3 questions- Case Study 2 Too Much Fatigue and Stres.docx
Please answer the 3 questions- Case Study 2 Too Much Fatigue and Stres.docx
 
Please answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docxPlease answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docx
 

Recently uploaded

1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Recently uploaded (20)

Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 

Please copy and paste the code and explain why it won't work- It is su.docx

  • 1. Please copy and paste the code and explain why it won't work. It is supposed to take a maze and return the exits and number of exits. import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Arrays; public class MazeSolver { int numRows; int numCols; int startRow; int startCol; int rows; int col; public static void loadMaze(){ int numRows; int numCols; int startRow; int startCol; int rows; int col; try{ Scanner input = new Scanner(System.in); System.out.println("Please enter file name:"); String filename = input.nextLine(); File file = new File(filename); Scanner fileInput = new Scanner(file); numRows = fileInput.nextInt(); numCols = fileInput.nextInt(); ArrayList column= new ArrayList<String>(); ArrayList row = new ArrayList<String>(); char[][] maze= new char[numRows][numCols]; //for the row, get array start row and column index for (int i = 0; i < numRows; i++) { String line = fileInput.next(); for (int j = 0; j < numCols; j++) { char empt = ' '; maze[i][j] = if (maze[i][j] == empt){ startRow = i; startCol = j; System.out.println(i); //solveMaze(maze[i][j]);
  • 2. } else{ return; } } } fileInput.close(); } catch(FileNotFoundException e) { System.out.println("File not found."); loadMaze(); } } // Method to solve the maze public void solveMaze(char[][] maze) { ArrayList<Integer> exitRows = new ArrayList<Integer>(); ArrayList<Integer> exitCols = new ArrayList<Integer>(); boolean[][] visited = new boolean[numRows][numCols]; // Call recursive method to explore the maze exploreMaze(startRow, startCol, visited, maze, exitRows, exitCols); // Print number of exits found System.out.println("Number of exits found: " + exitRows.size()); // Print positions of exits for (int i = 0; i < exitRows.size(); i++) { System.out.println("Exit found at: (" + exitRows.get(i) + ", " + exitCols.get(i) + ")"); } } public void exploreMaze(int row, int col, boolean[][] visited, char[][] maze, ArrayList<Integer> exitRows, ArrayList<Integer> exitCols) { // Recursive method to explore the maze if (row < 0 || col < 0 || row >= numRows || col >= numCols || visited[row][col]) { // Base case: if current position is out of bounds or already visited return; } // Base case: if current position is an exit if (maze[row][col] == 'E'){ exitRows.add(row); exitCols.add(col); return; }
  • 3. // Mark current position as visited visited[row][col] = true; exploreMaze(row-1, col, visited, maze,exitRows, exitCols); // up exploreMaze(row, col+1, visited, maze,exitRows, exitCols); // right exploreMaze(row+1, col, visited, maze,exitRows, exitCols); // down exploreMaze(row, col-1, visited, maze,exitRows, exitCols); // left // Recursively explore neighboring positions } }