QUESTION 2. myContains that returns true if elem is in the list and false otherw
ID: 3871033 • Letter: Q
Question
QUESTION 2. myContains that returns true if elem is in the list and false otherwise is given. >myContains(12,-8,1,3,411) True myContains(12,-8,1,3,410) False myContains(12,-8,1,3,414) True >>> mycontainsi 2,4,1,3,49 False Define a function myContainsindex(list,elem) that returns -1 if elem in not in the list. If elem is in the list, the function returns the index of list where elem is found in the list,. For example (compare against above): omyContainsindex([2,-8,1,3,411) myContainsindes12-8.1,3,4L0 xo myContainsindext(2-8,1,3,414) ox myContainslndex(2-8.1.3,415) > myContainsindext12-8.1,3,415) 25 31Explanation / Answer
In java in-built methods are available to do the same.
Please find the below snippet..
Source code
public boolean myContains(List<Integer> list,Integer i){
return list.contains(i);
}
public int myContainsIndex(List<Integer> list,Integer i){
if(myContains(list, i)){
return list.indexOf(i);
}else{
return -1;
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.