Bonjour a tous
voila c'est ma première participation dans ce beau forum
j'ai essayé d'ecrire un programme qui li les des entiers apartire du clavier ,aprés il va faire le tri de ces entiers ,alors le probléme lorsque j'exécute.. un message d'exception est affiché et j'ai pas pu savoir ou est le probléme ou bien l'erreur à traiter
merci beaucoup et voila le code
et voile le message:
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
31
32
33
34
35
36
37
38
39
40
41
42
43 import java.io.*; class clavier { static int x; static int tab[]=new int[5]; static int clavier()throws IOException { BufferedReader passmoi=new BufferedReader(new InputStreamReader(System.in)); int a=Integer.parseInt(passmoi.readLine()); return(a); } public static void main(String[]args)throws IOException { for(int i=0;i<tab.length;i++) { System.out.println("entrer la i eme valeur "); tab[i] =clavier(); //System.out.println(tab[i]); } for(int b=0;b<=tab.length;b++) { for(int j=b+1;j<=tab.length;j++) { if(tab[b]<tab[j]) { x =tab[j]; tab[j]=tab[b]; tab[b]=x; } } } for(int i=0;i<tab.length;i++) { System.out.println(tab[i]); } } }
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at clavier.main(m.java:26)
Partager