
640 CHAPTER 9 Multidimensional Arrays and the ArrayList Class
EXERCISES,PROBLEMS, AND PROJECTS
60. You coded the following in the Test.java class:
int [][]a = {{1, 2, 3, 4 },
{ 10, 20, 30 }};
for ( int i = 0; i < a.length; i++ )
{
for ( int j = 0; j < a[0].length; j++ )
{
System.out.println( a[i][j]); // line 14
}
}
The code compiles properly but when you run, you get the follow-
ing output:
1
2
3
4
10
20
30
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
at Test.main(Test.java: 14)
Explain what the problem is and how to fix it.
61. You coded the following in the Test.java class in order to output the
smallest element in the array a.
int [][] ...