bonjour,
je souhaite inverser un tableau
c'est la void ligne 28 qui me renvois
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
44
45
46
47
48
49
50
51
52
53
54 public class tableaux { public static void charger(int t[]){ for (int i=0;i<20;i++) { t[i]=(int)(Math.random() * (6-1)) + 1; Terminal.ecrireInt(t[i]); Terminal.sautDeLigne(); } } public static void trier(int t[]) { int max=0; for (int i=0;i<20;i++) { for (int j=i+1;j<20;j++) { if (t[j]<t[i]){ max=t[j]; t[j]=t[i]; t[i]=max; } } } } public static void inverse(int t[],int inv[]) { int k=0; for (int i=19;i!=0;i--) { inv[k]=t[i]; k=k+1; } } public static void affichage(int t[]){ for (int i=0;i<20;i++){ Terminal.ecrireInt(t[i]); }} public static void main(String[] args) { int tab[]=new int[20]; int inverse[]=new int [2]; charger(tab); trier(tab); affichage(tab); inverse(tab,inverse); affichage(inverse); System.out.println("Hello World!"); } }
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at tableaux.inverse(tableaux.java:42)
at tableaux.main(tableaux.java:58)
merci
Partager