
8.10.4 Identifying Errors in Code
37. Index –1 is out of bounds; the statement System.out.println( a[-1] );
will generate a run-time exception.
40. When declaring an array, the square brackets should be empty.
Replace a[3] by a[ ].
43. Although the code compiles, it outputs the hash code of the array a.
To output the elements of the array, we need to loop through the
array elements and output them one by one.
8.10.5 Debugging Area—Using Messages from the Java Compiler and Java JVM
46. Index a.length is out of bounds; when i is equal to a.length, the
expression
a[i] will generate a run-time exception. Replace <= with <
in the loop condition.
9.10 Exercise ...