Bonjour,

J'ai le code suivant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
Scanner sc = new Scanner(System.in);
char tableau[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm'};
char carac; char reponse; int i;
 
		do
		{ 
			do   // ligne 13
			{	
			i = 0;
			System.out.println("Entrez une lettre minuscule: ");
			carac = sc.nextLine().charAt(0);
//			while (i < tableau.length && carac != tableau[i])   // ligne 18
			while (carac != tableau[i] && i < tableau.length)   // ligne 19
				i++;
				//	if(i < tableau.length)      //  ligne 21
                                                                               if (carac != tableau[i])   //   ligne 22
					System.out.println("La lettre " + carac + " ne figure pas dans le tableau");
					else
					System.out.println("La lettre " + carac + " se trouve dans le tableau");
			}
			while(i >= tableau.length);
						do
						{
						System.out.println("Voulez-vous continer?: O/N");
						reponse = sc.nextLine().charAt(0);
						}
						while(reponse != 'O' && reponse != 'N');
		}
		while(reponse == 'O');
System.out.println("Bye Bye!!");
L'exécution affiche deux erreurs :
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 13
at Recherche_Tab.main(Recherche_Tab.java:19)
Ceci, lorsque j'entre un caractère ne se trouvant pas dans le tableau. Si je remplace la ligne 19 par la 18 et la 22 par la 21 tout marche: Pourquoi?

Merci de votre aide.