Méthode qui ne retourne pas la bonne valeur
j'ai fait cette fonction afin de faire la recherche d'une chaine de charactères dans un tableau de chaine de charactères , s'il trouve la chaine il retourne l'indice dans le tableau ou il a trouvè la chaine:roll:
voila mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| public int recherche(String ph , String[]table){
int ind=0;
boolean trouve=false ;
int i=0;
while((i<table.length) && (trouve=false)){
if (table[i]==ph){
ind=i;
trouve=true;
}
else i ++ ;
}
return ind ;
} |
:roll:
mais quand j'apelle cette fonction
Code:
1 2 3 4 5
| String mot="ecrire";
int y=recherche(mot,montable); // mon table est un tableau qui contient des
// chaines de charactères dont ecrire est
// la 4eme position
System.out.println(y); |
mais ca me retourne 0 :cry::cry::cry::cry::cry::cry:
je crois le probleme est dans la fonction mais je ne l'ai pa trouvé
J'en ai besoin dans mn projet