My return false statement doesn’t work as expected. I have a recursive method called “prosegui”, it works with most of the words i want to work with, but with a few of them the return false doesn’t return the value “false” as it should but continue and end up returning true.
if (contChar < this.parola.length() - 1) {
if (this.parola.charAt(contChar+1)==matrice[i][j])
{
prosegui(proseguiI,proseguiJ,i,j,contChar+1);
}
else
{
System.out.println("FALSE");
return false;
}
}
System.out.println("TRUE");
return true;
I really don’t know how to sort it out.
EDIT:
the program print both “FALSE” and then “TRUE”
EDIT:
public boolean prosegui(int i, int j, int proseguiI, int proseguiJ, int contChar)
{
if (contChar < this.parola.length() - 1)
{
int direzioneI=proseguiI-i;
int direzioneJ=proseguiJ-j;
i=proseguiI+direzioneI;
j=proseguiJ+direzioneJ;
int cont;
StringTokenizer st = new StringTokenizer(this.results);
cont=0;
char[][] matrice = new char[this.lung][this.lung];
while (st.hasMoreTokens())
{
matrice[cont]=st.nextElement().toString().toCharArray();
cont++;
}
if(this.parola.charAt(contChar+1)==matrice[i][j]){
prosegui(proseguiI,proseguiJ,i,j,contChar+1);
}
else
{
System.out.println("FALSE");
return false;
}
}
System.out.println("TRUE");
return true;
}
If this code is in the prosegui method, then when it calls itself here:
The true/false returned by this call is never used.