import java.util.Arrays; import java.util.Scanner; /** * Calcualtes the median of a numbered set of real values */ public class Solution { /** * Gets data from standard input */ private Scanner input; /** * Start the execution of the solution * @param args Command line arguments */ public static void main(String args[]) { Solution solution = new Solution(); solution.run(); } /** * Run the solution. This method is called from main() */ public void run() { // Create object to read data from standard input input = new Scanner(System.in); // Read the number of elements int size = input.nextInt(); // Create an array to store all the values double values[] = new double[size]; // Read all values for ( int index = 0; index < values.length; ++index ) { values[index] = input.nextDouble(); } // Sort all the values Arrays.sort(values); // The median is the value at the center if ( values.length % 2 == 1 ) { // The array has an odd number of elements, we have a value at the center System.out.printf("%.2f\n", values[ values.length / 2 ] ); } else { // We do not have a value at the center, so we calculate the average (mean) // of the two values around the center of the array double mean = ( values[values.length / 2 - 1] + values[values.length / 2] ) / 2.0; System.out.printf("%.2f\n", mean); } // Close the standard input input.close(); } }