Ask your own question, for FREE!
edX CS50x Intro to CS I 21 Online
OpenStudy (anonymous):

how do i write a method that takes an integer and an integer array and returns a Boolean indicating whether the integer can be found in the array or not in java

OpenStudy (anonymous):

If you can use an ArrayList instead, you can use the existing method 'contains'. If not, you could copy the implementation in java: public boolean contains(Object o) { return indexOf(o) >= 0; } where indexOf is: public int indexOf(Object o) { if (o == null) { for (int i = 0; i < size; i++) if (elementData[i]==null) return i; } else { for (int i = 0; i < size; i++) if (o.equals(elementData[i])) return i; } return -1; } If you know the list is sorted, you can use a binary search.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!