1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
import java.io.*;
class chap5_recherche {
public static void main(String[] args) {
String [] tab={"jean","pierre","paul","jack"};
int i=0;
String txt="";
boolean trouve=false;
BufferedReader saisie;
saisie=new BufferedReader(new InputStreamReader (System.in));
try{
System.out.println("Entrez le prenom recherche :");
txt=saisie.readLine();
}
catch (Exception excp) {
System.out.println("Erreur");
}
while(i<tab.length && !trouve) {
if(tab[i].equals(txt)){
trouve=true;
break;
}else
i++;
}
if(trouve) System.out.println("Trouve a la position "+(i));
else System.out.println("Ce nom ne figure pas dans la liste !");
}
} |
Partager