CSC300: Does this work? [12/14] Previous pageContentsNext page

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
  public static int numFives (double[] a) {
    return numFives(a, 0, 0);
  }
  private static int numFives (double[] a, int i, int result) {
    if (a.length == 0) {  
      return 0;
    }
    if (a.length < 2) {
      if (a[0] == 5) result++;
      return result;
    }
    if (i < a.length) {
      if (a[0] == 5) result++;
      return numFives(a, i+1, result);
    } else {
      return result;
    }   
  }

Previous pageContentsNext page