Bonjour ,
je suis en premiere année de licence maths-info et j'ai eu ce sujet en tp
hier :J'ai donc fait ce programme :Ecrire une méthode qui prend comme arguments deux tableaux
t1 et t2 et qui construit et renvoie un tableau tcontenant les elements de t1 suivis des elements de t2.
Le probleme c'est que en executant le programme j'obtient toujours :
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 mport fr.jussieu.script.*; class Concatene { public static int[] litTableau (int n) { int[] t = new int [n]; for (int i = 0; i < t.length; i++) { Deug.print("Donnez-moi l'entier " + i + " > "); t[i] = Deug.readInt(); } return t; } public static int[] concatene(int x ,int y) { int [] t1 = litTableau(x); int [] t2 = litTableau(y); int [] t = t1; int p =t.length+1; for (int i = 0; i < t2.length ; i++) { t[p]= t2[i]; p=p+1; } return t; } public static void main (String[]args) { int x = Deug.readInt(); int y = Deug.readInt(); int[] t = concatene ( x , y ); for( int i = 0; i < t.length; i++){ Deug.print( t[i] ); Deug.print(' '); } } }
Est-ce que l'on peut m'expliquer a quoi et due cette erreur et comment puis-je la corriger ?Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6
at Concatene.concatene(Concatene.java:18 )
at Concatene.main(Concatene.java:26)
Merci
Partager