difficult exercise in racket sheme programming??????????
A function named occurrences that takes as parameters two arguments, a and b. If a is not a list
then the function should return #f. Otherwise it should return the number of times b is found in
the list a. For example, if a is (3 4 2 53 3 5 4) and b is 3 the function should return 2
1
Expert's answer
2012-04-26T07:38:01-0400
public static int occurrences(ArrayList<Integer> a, int b){ if (a.getClass().getName().equals("java.util.ArrayList")){ int k=0; for (int i=0;i<a.size();i++) if (a.get(i)==b) k++; return k; }else return -1; }
Comments
Leave a comment