-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day 0
48 lines (43 loc) · 1.24 KB
/
Day 0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
float[] arr = new float[n];
int[] count = new int[n];
float sum = 0;
for(int i=0;i<n;i++){
count[i] =0;
arr[i] = scan.nextInt();
sum = sum + arr[i];
}
Arrays.sort(arr);
float mean = sum/n;
float median;
System.out.println(mean);
if(n%2==0)
median = (arr[n/2] + arr[n/2-1])/2;
else
median = arr[n/2];
System.out.println(median);
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(arr[i]==arr[j]){
count[i]++;
arr[j]=-1;
}
}
}
int max =0;
float mode = arr[max];
for(int i=0;i<n;i++){
if(count[i]>max){
max = count[i];
mode = arr[i];
}
}
System.out.println(mode);
}
}