AP Computer Science Quiz: Arrays Name: ___________________________
Date: 12/11/08 1) What is the output of the following segment of code?
int[] vals = new int[5];
for (i=0; i<5; i++)
vals[i] = 3*i + 4;
for (i=0; i<3; i++) {
int t = vals[4-i];
vals[4-i] = vals[i];
vals[i] = t;
}
for (i=0; i<5; i++)
System.out.print(vals[i]+" ");
System.out.println();
__________________________________
2) What is the output of the following segment of code?
int[] a = new int[2];
a[0] = 4; a[1] = 7;
int[] b = a;
b[1] = 9;
System.out.println(a[0]+" "+a[1]+" "+b[0]+" "+b[1]);
___________________________________
3) Write a method that returns the minimum value stored in the array passed to it. Fill in the method below:
public static int minVal(int[] array) {