Answer to Question #8708 in Java | JSP | JSF for RACKET SCHEME

Question #8708
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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS