Hey guys looking for some help with my ArrayTester class...
The array is supposed to
1.create a 20 element int array and populates it with random elements in the range 20 through 65 (both inclusive).
-I Believe I have already done this.
2.Use the java.util.Random class with a seed of 2621 to generate repeatable output for the data.
-I have also already done this
3.The tester class should then test each of these methods(mean, median, mode, max, min, standard divination)
-this is where I'm having trouble, I already have the code for the mean, mode, max, min, and standard divination.. the problem I'm having is with the median as i would like to sort my array in the tester class before having it called by my main Class.
If you're asking whether it's possible to sort an array, then yes, of course it is.
Are you supposed to write code from scratch which sorts the array, or are you allowed to use a method from the standard API which sorts the array?
Joined: Feb 06, 2013
If your talking about Arrays.sort() then yes I am! however I'm having trouble even with that, as of right now when I put the Arrays.sort(numbers); outside the for loop nothing changes when I outprint the array (the numbers are still printing out, they're just not sorted) This made me believe that I had to also move my System.out.println(numbers[i]) outside the for loop as well. However when I do this I get an error saying that it cannot find the variable [i]
vinay chaturvedi wrote: . . . You can not store the sorted array as the Array.sort() method returns void.
You have misunderstood how the sort method works. It takes an array as its parameter and alters the state of that array. That is rather like an output parameter.
You can store the sorted array, because it is the same array you started off with.
If you are not using a toString method, you should use a for‑each loop to print that array.