I have an assignment which requires me to create a method that will search through an array for a target value and print all the indexes it occurs at in a new array. The parts im having the most trouble with is creating a new array to hold the values of the indexes that are found. Any ideas? Thanks.
Do you really have to create a separate array? If the assignment is just to print the indexes that match, can you just iterate through the array and print out an index as you find equal values? Or you can build a String that holds the output, and print the String at the end of the method.
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
If you don't know what size the array is going to be, it will be annoying. You can still make an array whose size if as big as the input array. Otherwise, I think you'll have to loop twice, once to get the number of matching indexes, and another one to store the indexes. Can you figure this out ?