Q:

using Linear Search ,Write a method that returns the index of the first occurrence of given integer in a list

0

Write a method that returns the index of the first occurrence of given integer in a list.
Assume that the index of the first element in the list is zero.
If the number does not exist return -1.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

public int search(Integer n, Integer[] list) {

int index = -1;

for (int i = 0; i < list.length; i++) {

    if (list[i].equals(n)) {

        index = i;

        break;

    }

}

return index;

}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now