Array Tracing
1. What prints when main is run:
public static void main(){
int[] x = {1,2,3,4,0};
System.out.println(mystery1(x));
System.out.println(mystery2(x,3));
System.out.println(mystery3("ABC DEF") + 3);
}
public static double mystery1(int[] numbers) {
int sum = 0;
for (int i = 0; i < numbers.length; i++) {
sum += numbers[i];
}
return (double) sum / numbers.length;
}
public static boolean mystery2(int[] values, int target) {
for (int i = 0; i < values.length; i++) {
if (values[i] == target) {
return true;
}
}
return false;
}
public static int mystery3 (String one )
{
String[] oneA = one.split(" " ) ;
return oneA.length;
}
5. Answer the questions below:
int count = 1;
int[][] foo = new int[2][3];
for (int i = 0; i < foo.length; i++)
{
for (int j = 0; j < foo[i].length; j++)
{
foo[i][j] = count + i + j;
count = count + 1;
}
}
What will be the values in the array when this code completes?
foo[0][0] = ____
foo[0][1] = ____
foo[0][2] = ____
foo[1][0] = ____
foo[1][1] = ____
foo[1][2] = ____