Array Tracing

1. What prints when main is run:

Answer:

2.0
true
5

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] = __1__
•foo[0][1] = _3___
•foo[0][2] = __5__
•foo[1][0] = _5___
•foo[1][1] = __7__
•foo[1][2] = ___9_