62-9. You coded the following in file Test.java:
int [ ] [ ] a = { { 9, 8, 7, 6 },
{ 10, 20, 30, 40 } };
for ( int j = 0; j <= a[1].length; j++ )
{
if ( a[1][j] == 20 ) // line 14
{
System.out.println( "Found 20 at column index " + j
+ " of second row" );
}
}
The code compiles properly, but when you run, you get the following output:
Found 20 at column index 1 of second row
Exception in thread "main" java.lang.ArraylndexOutOfBoundsException:
at Test.main(Test.java:14)
Explain what the problem is and how to fix it.