Bonjour,

J'ai un problème pour initialiser mon Array. Je veux avoir résultat suivant:
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Mais j'ai erreur en compilant mon programme :
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at TestArrays2.main(TestArrays2.java:17)
voilà mon prg
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
 
public class TestArrays2 
{
	public static void main(String[]args)
	{
		int i;
		int j;
 
		int table [][]=new int [5][5];
		for(i=0;i<5;i++)
		{
			for(j=0;j<5;j++)
			{
				if(i==j)
					table[i][j]=1;
				else
					table[i][j]=0;	
			}
			System.out.print(i);
			System.out.print(j);
		}
	}
Veuillez m'aider s'il vous plait. Voici le résultat que je obtiens :
0515253545
Mais je veux :
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1