I'm studying basic Java and I there's a question on a programming assignment that I'm having a lot of trouble with concerning recursive overloading of sort of a search method. Here's what I'm being asked to do:
Write a method that accepts a two-dimensional int[][] array as the parameter and searches for legal "paths" through it, starting at [0][0] and ending at the end of the array. (For instance if the array is declared [5][5] then the end would be [4][4]).
In order for a path to be legal, "jumps" must be performed between the cells until the end of the array is reached. If a path doesn't end at the end of the array, it isn't legal. Here's an example:

The logic here is that a "jump" can be performed either to the right by the 10s and down by the 1s place of the number in the cell or vice versa, and the goal of the method is to return the number of legal pathways that exist through the array.
This wouldn't really be so much of a problem if it wasn't for the fact that the professor has several requirements for the assignment:
1) Absolutely no loops - the method must be carried out completely through recursion. 2) No global or constant variables 3) No changing the contents of the array or duplicating it 4) No creating or using other methods - overloading is encouraged (and probably required at this point) but writing a new method to assist in the process is out of the question.
Here's what I have so far:
public class Question4 {
//step 1 - location: [0][0]
public static int countPaths(int[][] mat) {
int current = mat[0][0];
//case 1: x < 10
if(current < 10) {
//check right
if(current < mat.length-1) {
return countPaths(mat, current, 0, 0);
}
//check left
if(current < (mat[0].length-1)) {
return countPaths(mat, 0, current, 0);
}
//case 2: x >= 10
} else if(current >= 10) {
int tens = (int)(Math.floor(current / 10));
int ones = current % 10;
//check down by 10s, right by 1s
if(tens < mat.length-1 && ones < mat[0].length-1) {
return countPaths(mat, tens, ones, 0);
}
//check right by 10s, down by 1s
if(ones < mat.length-1 && tens < mat[0].length-1) {
return countPaths(mat, ones, tens, 0);
}
}
return 0;
}
//step 2 - two options: down by 10s, right by 1s / right by 10s, down by 1s
public static int countPaths(int[][] mat, int r, int c, int paths) {
//check if the end of the array has been reached
if(r == mat.length-1 && c == mat[r].length-1) {
return paths + 1;
} else {
int current = mat[r][c], tens = (int)Math.floor(current / 10), ones = current % 10;
//check down by 10s, right by 1s
if(r + tens < mat.length-1 && c + ones < mat[r].length-1) {
return countPaths(mat, r + tens, c + ones, paths);
}
//check down by 1s, right by 10s
if(r + ones < mat.length-1 && c + tens < mat[r].length-1) {
return countPaths(mat, r + ones, c + tens, paths);
} else {
return paths;
}
}
}
}
I do apologize for the long question - I've been stuck on this thing for a week and haven't been able to figure it out.
The array in the photo should give a result of 3 possible paths, but every time I run the method I get 0.
Any help at all would be greatly appreciated. Thank you :)