So I am extremely new to Java and my assignment has me creating an array 10 indexes in size, copying it, and sorting the copy. These parts I have functioning properly. What they want me to do is prompt the user for a value they wish to search for, and if found, return the index and which array it was found in. This last search part is really messing me up. My code is very sloppy I know, but I am not very good at this yet. The book of course has an example, but it uses a driver class and I'm not entirely sure if that's required in this situation. Thanks for any replies and my apologies if I posted this incorrectly.
https://i.stack.imgur.com/My6BC.jpg - This is an example of the final output required.
public class MJUnit1Ch9 {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
double[] numList; //list of random numbers
double[] numListSorted; //sorted copy of array
int numSearch; //array search
int numSearchIndex; //position in array
numList = new double[10]; //creation of size 10 array
for (int i = 0; i < 10; i++) { //create random numbers between 1 and 20
numList[i] = (int) (Math.random() * 20 + 1);
}
numListSorted = Arrays.copyOf(numList, numList.length); //copy original array
Arrays.sort(numListSorted); //sort copy by API
System.out.printf("%7s%7s\n", "Unsorted Array", "Sorted Array");
for (int i = 0; i < numList.length; i++) {
System.out.printf("%7.2f%7.2f\n", numList[i], numListSorted[i]);
}
//*************************************************************************
//*************************************************************************
System.out.print("Please enter number to search for:");
}
}