The exam is cumulative and may include material covered in the first set of problems and in the first midterm.
Be able to trace through any method in this slide set.
public class WhatsPrinted1 {
public static void whatsPrinted(int A[]) {
for (int i=1; i<A.length; i++) {
A[i]=A[i-1]*2+1;
}
}
public static void main(String args[]) {
int A[] = {12,3,8,9,7,11};
whatsPrinted(A);
System.out.println(A[A.length-1]);
}
}
public class WhatsPrinted2 {
public static void whatHappens(int A[]) {
int []B = new int[A.length];
for (int i=0; i<A.length; i++) {
B[i]=A[i]*2;
}
A=B;
}
public static void main(String args[]) {
int A[] = {10,20,30};
whatHappens(A);
System.out.println(A[0]);
}
}
public class WhatsPrinted3 {
public static int[] whatHappens(int A[]) {
int []B = new int[A.length];
for (int i=0; i<A.length; i++) {
B[i]=A[i]*2;
}
return B;
}
public static void main(String args[]) {
int A[] = {10,20,30};
whatHappens(A);
System.out.println(A[0]);
}
}
public class WhatsPrinted4 {
public static int[] whatHappens(int A[]) {
int C[]=new int[A.length];
for (int i=0; i<A.length; i++) {
C[i]=A[i];
}
return C;
}
public static void main(String args[]) {
int A[]={10,20,30};
int B[]=whatHappens(A);
if (A==B) {
System.out.println("equal");
} else {
System.out.println("not equal");
}
}
}
Stan 99 87 100
Dipper 100 100 97 100
Mabel 100 100
Seuss 72 85 65
the method returns the average of the student with the highest semester average.
/* sets every value in A[][] to initVal */
public static void initialize(int A[][], int initVal)
/* returns the largest element in A */
public static int largestItem(int A[][])
/* returns the sum of the row in A that has the largest
* sum. */
public static int largestRow(int A[][])
/* Returns column i of A as an array. For example, if */
/* A[][] is: */
/* |-----+-----+-----+-----+-----| */
/* | 10 | 20 | 30 | 40 | 50 | */
/* |-----+-----+-----+-----+-----| */
/* | 60 | 70 | 80 | 90 | 100 | */
/* |-----+-----+-----+-----+-----| */
/* | 110 | 120 | 130 | 140 | 150 | */
/* |-----+-----+-----+-----+-----| */
/* and i is 1, the method returns the array */
/* */
/* |----+----+-----| */
/* | 20 | 70 | 120 | */
/* |----+----+-----| */
/* */
/* You may assume that every row has */
/* the same number of columns. */
public static int[] getCol(int A[][], int i)
/* returns the sum of the column in A that has the largest
* sum. You may assume that each row has the same number
* of columns. */
public static int largestCol(int A[][])