Question: Need to find the Median in JAVA import java.util.Arrays; class Main { public static void main (Stringargs [ ]) { int numbers [ ] =

Need to find the Median in JAVA

import java.util.Arrays;
class Main
{
public static void main (Stringargs [ ])
{
int numbers [ ] = {1,5,-9,12,-3,89, 18,23,4,-6};
// Find minimum (lowest) value in array using loop

System.out.println("Minimum Value = " + getMinValue(numbers));
//Find maximum (largest) value in array using loop

System.out.println("Maximum Value = " +getMaxValue(numbers));

// Find average value in array usingloop

System.out.println("Average Value = " +getAvgValue(numbers));

// Addany challenge method calls here ....


Arrays.sort(numbers);
// Print the sortedarray
System.out.println("The sorted array: ");
for (int i = 0; i {
System.out.println (numbers[i]);
}
}


// Find maximum (largest) value inarray using loop
public static int getMaxValue ( int [ ] numbers) {

intmaxValue = numbers [0];

// Access each array element starting with the secondelement
for(int i = 1; i < numbers.length; i++){
if (numbers [ i ] > maxValue) { // is the current element greater than the current maxvalue?
maxValue = numbers [ i ]; // the current element is now the max value
} // end if
} // end for

returnmaxValue; // return the largest array element value

} // getMaxValue


// Find minimum (lowest) value in array usingloop
public static int getMinValue( int [ ] numbers) {

intminValue = numbers [ 0 ];

// Access each array element starting with the second element
for(int i = 1; i < numbers.length; i++){
if (numbers [ i ] < minValue) { // is the current element less than the current minvalue?
minValue = numbers [ i ]; // the current element is now the min value
} // end if
} // end for

returnminValue;

} // getMinValue


// Find the average of an array ofintegers

public static double getAvgValue ( int [ ]numbers) {

doubleaverage = 0;
double sum= 0;

//ADDCODE TO ADD A LOOP TO COMPUTE A RUNNING TOTAL OF ALL ARRAYELEMENTS

for (int i = 0; i < numbers.length; i++) {
sum = sum + numbers [ i ];
} // end for

// ADD CODE TO COMPUTE THE AVERAGE
average =sum / numbers.length;
returnaverage;

} // getAvgValue

// Add any Challenge methods here ...

} // Main Class

Step by Step Solution

3.47 Rating (160 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Java program to calculate and display the minimum maximum average median and sorted array of integers import javautilArrays class Main public static v... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Electrical Engineering Questions!