View as "text/plain" | Blame | Last modification | View Log | RSS feed
package com.spice.profitmandi.common.services.mandii;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.Arrays;import java.util.List;import java.util.stream.Collectors;public class Solution {public static void main(String[] args) throws IOException {BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));int length = Integer.parseInt(bufferedReader.readLine());List<Integer> row = Arrays.asList(bufferedReader.readLine().split(" ")).stream().map(x -> Integer.parseInt(x)).collect(Collectors.toList());double total = 0;int maxNum = 0;for (int num : row) {total += num;if (maxNum < num)maxNum = num;}System.out.println(String.format("%.1f",total / length));double median = length % 2 == 0 ? (double)(row.get((length - 1) / 2) + row.get((length + 1) / 2) / 2) : row.get(length / 2);System.out.println(String.format("%.1f",median));int[] arr = new int[maxNum+1];for (int num : row) {arr[num]++;}int mode = 0;int frequency = 0;for (int i=0; i< maxNum; i++) {if(arr[i] > frequency) {mode = i;frequency = arr[i];}}System.out.println(mode);}}