CS 1401, Quiz #13

Date: Tuesday, April 26, 2005
Section: (starting 9 am or starting 10:30 am) ______________________________________________________________________

Name (please type legibly, ideally in block letters): ______________________________________________________________________

1. Write down a code that, given two arrays a and b of the same size, returns their component-wise difference, i.e., an array c for which c[0]=a[0]-b[0], c[1]=a[1]-b[1], ...

for (int i = 0; i < a.length; i++) 
  c[i] = a[i] - b[i];
2. Write down a method that, given an array a, returns the number of all positive elements of this array.
public static int numPositive (int[] a){
  int number = 0; 
  for (int i = 0; i < a.length; i++) 
    if (a[i]>0) number++; 
  return number; 
}