I need help with a little array assignment that I am currently doing. So far I managed to correct alof of code but this one problem still remains..
public class AssignmentArray1 {
public static void main(String[] args) {
int a[][] = new int[ 10 ][ 5 ];
for ( int i = 0; i < a.length; i++ )
{
for ( int j = 0; j < a[ i ].length; j++ ) {
a[ j ][ i ] = j;
}
}
for ( int i = 0; i < a.length; i++ )
{
for ( int j = 0; j < a[ i ].length; j++ )
System.out.printf( "%d ", a[ j ][ i ] );
System.out.println();
}
}
}
What's wrong with this? I can't understand why I'm getting the error message
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5 at assignmentarray1.AssignmentArray1.main(AssignmentArray1.java:25)
So obviously something is wrong with a[ j ][ i ] = j;? But exactly what is?
a[ j ][ i ]bya[ i ][ j ](in both loops)