lor d'une compilation, j'ai erreur ArrayIndexOutOfBoundsException: 3
bonjour
mon prg donne erreur message lors d'une compilation ArrayIndexOutOfBoundsException: 3
veuillez aidez svp
Code:
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
|
import java.util.Scanner;
public class TriBulle
{
public static void main(String[] args)
{
//int t[] =new int[100];
int n,x;
Scanner sc= new Scanner(System.in);
System.out.print("Entrez le nombre d'éléments du tableau :");
n=sc.nextInt();
int t[] =new int[n];
for(int i=0;i<n;i++)
{
System.out.print("Entrer l'élément n°"+(i+1)+" du tableau :");
t[i]=sc.nextInt();
}
System.out.print("Entrez la valeur de l'élément à ajouter");
x=sc.nextInt();
n=n+1;
//t[n−1]=x;
t[n-1]=x;
for(int i=0;i<n;i++)
{
System.out.println("L'élément t["+(i+1)+"] est :"+t[i]);
}
}
} |