X1275: Linear Search (Strings) Return Index

Complete the following linear search method. Find the string search in the array words. If the string is found, return the index for the position. If it is not found, return -1. It is unspecified if the array is ordered or not, so assume it is not.

Examples:

linearSearch({"Charlotte", "Raleigh", "Greensboro"},"Charlotte") -> 0
linearSearch({"Charlotte", "Raleigh", "Greensboro"},"Durham") -> -1
linearSearch({"Charlotte", "Raleigh", "Greensboro"},"Greensboro") -> 2

Your Answer:

Reset

Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.