Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
13 views2 pages

Testing

The document contains a Java class named 'Testing' that includes methods to find all paths in a maze, count the number of unique paths to a destination, and print specific paths. The 'Allpaths' method recursively explores possible movements in a maze represented by a 2D boolean array. The 'count' method calculates the number of ways to reach the top-left corner of the maze, while 'printPath' outputs the paths taken to reach the destination.

Uploaded by

rahulsuthrapu616
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Testing

The document contains a Java class named 'Testing' that includes methods to find all paths in a maze, count the number of unique paths to a destination, and print specific paths. The 'Allpaths' method recursively explores possible movements in a maze represented by a 2D boolean array. The 'count' method calculates the number of ways to reach the top-left corner of the maze, while 'printPath' outputs the paths taken to reach the destination.

Uploaded by

rahulsuthrapu616
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

public class Testing {

static void Allpaths(String P,boolean maze[][],int r, int c){


if(r==maze.length-1 && c==maze[0].length-1){
System.out.println(P);
return;
}
if(maze[r][c]==false){
return;
}

maze[r][c]=false;

if(r<maze.length-1){
Allpaths(P+"D", maze, r+1, c);
}
if(c<maze[0].length-1){
Allpaths(P+"R", maze, r, c+1);
}
if(c>0){
Allpaths(P+"L", maze, r, c-1);
}
if(r>0){
Allpaths(P+"U", maze, r-1, c);
}

maze[r][c]=true;

static int count(int r,int c){


if(r==1||c==1){
return 1;
}
int left=count(r-1,c);
int right=count(r,c-1);
int cross=count(r-1,c-1);
return left+right+cross;
}

static void printPath(String p,int r,int c){


if(r==1 && c==1){
System.out.println(p);
return;
}

if(r>1){
printPath(p+"D", r-1, c);
}
if(c>1){
printPath(p+"R", r, c-1);

}
if(r>1 && c>1){
printPath(p+"C", r-1, c-1);

public static void main(String[] args) {


boolean maze[][]={
{true,true,true},
{true,true,true},
{true,true,true}
};
System.out.println(count(3,3));

printPath(" ", 3, 3);


}

You might also like