/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package e78;
import java.util.Arrays;
import java.util.Scanner;
/**
*
* @author student
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("How many numbers in the array?: ");
int n = scanner.nextInt();
double[] array = new double[n];
int i;
for (i = 0; i < n; i++) {
Scanner in = new Scanner(System.in);
System.out.print("Enter a number in the array: ");
array[i] = in.nextDouble();
}
Arrays.sort(array);
int middle = array.length/2;
System.out.println("Median = " + array[middle]);
}
}
No comments:
Post a Comment