array continue to print after the key number is found in the array
Can you please explain this?
if you would like return the key you can do it once all elements are printed.you can store key in temporary variable and return it from method once the array finish the printing.
Adam Gomez wrote:...The goal of the first part of the homework is to make the array continue to print after the key number is found in the array. At the moment it stops after the number entered is found.
Your code stops printing after the number entered is found, because as soon as you find element in the array you return it from your method. A good way to accomplish what you want is the one proposed by jatan, but with slight modification. There is no need to keep a temp variable to return the value you are searching from your search method (you have a value you are searching as argument to method call). I would rather keep the index (position) of the element found if it exists in an array, and -1 otherwise. After you complete with for loop, just return that temp value, and by knowing the index of the value you can access it any time.