Computer Science › Run Time Errors
Consider the following code:
Object[] objects = new Object[20];
for(int i = 0; i < objects.length; i++) {
switch(i % 4) {
case 0:
objects[i] = new Integer(i + 3);
break;
case 1:
objects[i] = "This val: " + i;
break;
case 2:
objects[i] = new Double(i * 4.4);
break;
case 3:
objects[i] = "That val: " + (i*12);
break;
}
}
String s = (String)objects[8];
System.out.println(s);
What is the error in the code above?
public static int[][] doWork(int[][] a, int[][] b) {
int[][] ret = new int[a.length][a[0].length];
for(int i = 0; i < a.length; i++) {
for(int j = 0; j < a[i].length; j++) {
ret[i][j] = a[i][j] + b[i][j];
}
}
return ret;
}
In the code above, what is the potential error that will not be caught on the following line?
_ret[i][j] = a[i][j] + b[i][j];_