Answer:
The program of this question can be given as:
Program:
import java.util.*; //import package.
class Main //define class.
{
public static double mean(int x[], int n) //define function mean
{
//function body.
int total = 0;
for (int k = 0; k < n; k++)
total =total+ x[k];
return (double)total / (double)n; //return value.
}
public static int mini(int[] a, int n) //define function mini
{
//function body.
int result = a[0];
for(int k=0; k<n; k++)
if(result > a[k])
//result value
result = a[k];
return result;
}
public static int maxi(int[] a, int n) //define function maxi
{
//function body.
int result = a[0];
for(int k=0; k<n; k++)
if(result < a[k])
//result function
result = a[k];
return result;
}
public static double median(int x[], int n) //define function median
{
//function body.
Arrays.sort(x);
if (n % 2 != 0)
//return value
return (double)x[n / 2];
return (double)(x[(n - 1) / 2] + x[n / 2]) / 2.0;
}
//define main function.
public static void main(String ar [])
{
Scanner object = new Scanner(System.in); //creating Scanner class object.
System.out.print("Enter total students: "); //print message.
int n = object.nextInt();
int[] grades = new int[n];
System.out.print("Enter number of students: ");
for(int j=0; j<n; j++) //use loop for input number.
grades[j] = object.nextInt();
//calling function and print values.
System.out.println("Mean = " + mean(grades, n));
System.out.println("Median = " + median(grades, n));
System.out.println("Highest = " + maxi(grades, n));
System.out.println("Lowest = " + mini(grades, n));
}
}
output:
Enter total students: 4
Enter the number of students: 70
80
69
89
Mean = 77.0
Median = 75.0
Highest = 89
Lowest = 69
Explanation:
In the above program firstly we import package that is used for input from the user. Then we define a method that is mean,median, highest and lowest. The working of the method is the same as the name. All functions return to value main function. At last, we define the main function. In this function, we create the scanner class object for user input. Then we pass the value to function and print it.