# 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

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

Expert's answer

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;

}

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 orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment