|
Sample final questions |
Listed below are questions similar to those I will put on the midterm. Sample solutions will be posted Thursday.
public static int find(int[] A, int key)
that searches for the value of key in the array A and returns its index if it's there
but -1 if it's not.
public static int minimum(int i, int j, int k)
that returns the smallest of i, j, and k.
public class ExampleProgram { public static void fillArray(int[] A) { for (int i = 0; i < A.length; i++) { A[i] = i*i; } } public static int processArray(int[] A) { int s = 0; for (int i = 0; i < A.length; i++) { s += A[i]; } return s; } public static void main(String[] args) { int[] A = new int[10]; fillArray(A); System.out.println(processArray(A)); System.exit(0); } }