Hey all. Sorry to make something like this my first post, but I can't for the life of me figure out what exactly I'm supposed to change for my assignment. 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. I've tried messing with the return in the search part of the program, but nothing seems to get the array to continue printing. Any advice would be greatly appreciated.
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.
The quieter you are, the more you are able to hear.
You totally ruined the moon. You're gonna hafta pay for that you know. This tiny ad agrees: