initialiser un tableau à deux dimensions
Bonjour,
j'essaie d'afficher le contenu d'un tableau à deux dimensions, mais un message d'erreur apparaît:
java.lang.ExceptionInInitializerError
Je ne vois pas où est mon erreur, je pense que j'ai bien intialisé le tableau.
Voici le code
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
public class Tableau {
int x=1;
int [][] tab = new int[3][5];
public Tableau(){
for (int i=0; i<=tab.length;i++)
for (int j=0; j<=tab[i].length;j++)
tab[i][j]=2+x;
}
public void Affiche(){
for (int i=0; i<=tab.length;i++)
for (int j=0; j<=tab[0].length;j++)
System.out.println(" " + tab[i][j]);
}
} |
et pour le main
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
public class AfficheTableau {
static Tableau table = new Tableau();
public static void main (String [] args){
table.Affiche();
}
} |
Des idées?
Merci