In: Computer Science
Create global variables Mean, Mode, Median, then create a method that takes an array of 10 double numbers and return three answers of the Mean, Median, Mode ( no need for implementation of the mean, median and mode, calculate them manually and return the answers), assign the answers to the global variables.
In java, please!!
The following is the code for above question. As it is stated in the question that there is no need to implement the logic for mean,median and mode, I just manually calculated for given array and assigned to global varibales. In java, inorder to declare a variable global, we have to declare it using static keyword at start of the code.
import java.util.*;
public class Main
{
public static double Mean,Median,Mode;
public static void main(String[] args) {
double[] values = new double[]{2.5,4.42,5.2,2.1,6.2,3.4,5.9,6.1,9.3,2.5}; //double array of values
calculate(values);
System.out.println("Mean is "+Mean);
System.out.println("Median is "+Median);
System.out.println("Mode is "+Mode);
}
public static void calculate(double[] values)
{
Mean=4.084;
Median=5.2;
Mode=2.5;
}
}
Output:
Mean is 4.084
Median is 5.2
Mode is 2.5
#Please dont forget to upvote if you find the solution
helpful. Feel free to ask doubts if any, in the comments section.
Thank you.