Bonjour
Aprés execution de mon programme ci dessous, il ya cette erreur qui s'affiche :Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException : 4 at TestTableauEntiers.main(TestTableauEntiers.java:21)
D'aprés ce que j'ai compris,il ya un dépassement du tableau..mais je ne vois pas ou, pouvez vous m'aider?
Existe t-il un debugger en java?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 class TableauEntiers { public static int somme(int[]tab){ int s = 0; for(int i = 0; i<tab.length; i++) s += tab[i]; return s; } }
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 public class TestTableauEntiers{ private static void usage(){ System.err.println("usage : somme.."); System.exit(1); } public static void main (String[]args){ int i; if(args.length == 0) usage(); else { int[]tab= new int[args.length]; for (i=0; i<=tab.length ; i++); tab[i]= Integer.parseInt(args[i]); System.out.println( "somme" +TableauEntiers.somme(tab)); } } }
Partager