Hey everyone, having some troubles getting this down mostly step 4 i believe i have everything else correct not sure though. Im not sure how i would go by doing step 4 i can have it print the 9th value but im lost after that..
Create a one-dimensional array of 99 double values. Then, use a for loop to add a random number from 0 to 100 to each element in the array. For each value, use the random method of the Math class to get a double value between 0.0 and 1.0, and multiply it by 100.
Use an enhanced for loop to sum the values in the array. Then, calculate the average value and print that value on the console followed by a blank line. Compile and test this class.
Use the sort method of the Arrays class to sort the values in the array, and print themedian value (the 50th value) on the console followed by a blank line. Then, test this enhancement.
4 .Print the 9th value of the array on the console and every 9th value after that. Then,test this enhancement
import java.util.Arrays;
public class ArrayTestApp
{
public static void main(String[] args)
{
double[] testArray = new double [99];
//add a random number to each element in the array
for (int i=0; i < testArray.length; i++)
testArray[i] = 100.0*Math.random();
//sum the values and print out the average
double average = 0.0;
for(int i = 0; i < testArray.length; i++)
average += testArray[i];
average /= 99;
System.out.println("Average is: " + average);
System.out.println();
//sort the values and print the median
Arrays.sort(testArray);
System.out.println("Median is: " + testArray[testArray.length/2]);
System.out.println();
//print the 9th value and every 9th value after
}
}