CSC300: Common mistakes: Does this work? [12/17] Previous pageContentsNext page

11
12
13
14
15
16
17
18
19
20
21
22
23
  public int numFives () {
    if (first == null) return 0;
    int result = 0;
    if (first.item == 5.0) 
      result = result + 1;
    Node x = first;
    while (x.next != null) {
      if (x.next.item == 5.0)
        result = result + 1;
      x.next = x.next.next; 
    }
    return result;
  }

Previous pageContentsNext page