Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at tableau.main(tableau.java:12)
Bonjour tous le monde,
Je veux ecrire un programme qui place les nombres passés en paramètres dans un tableau, puis calcule et affiche le minimum, le maximum et la somme de ces nombres.
j'ai trouvé cette solution:
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
|
public class tableau {
/**
* @param args
*/
public static void main(String[] args) {
int[] t =new int[args.length] ;
for( int i=0;i<=args.length;i++)
{
System.out.print("t["+(i+1)+"]=");
t[i]=Integer.parseInt(args[i]);
}
int max=t[0],min=t[0];
for(int i=1;i<args.length;i++)
{
if (t[i]>max)
max=t[i];
if (t[i]<min)
min=t[i];
}
System.out.println("le min = "+min);
System.out.println("le max = "+max);
}
} |
cependant j'ati cette exception :
Code:
1 2 3 4
|
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at tableau.main(tableau.java:12)
t[1]= |
J'ai besoin de votre aide, Merci.