# baekjoon 2108

0_23·2022년 12월 14일
0

## [BOJ][Java]

목록 보기
49/55

import java.io.BufferedReader;
import java.io.IOException;
import java.util.Arrays;

class Main {
public static void main(String[] args) throws IOException {
StringBuilder sb = new StringBuilder();
int sum = 0;
int min = Integer.MAX_VALUE;//Integer.MAX_VALUE = 2147483647
int max = Integer.MIN_VALUE;//Integer.MIN_VALUE = -2147483648
int[] arr = new int[8001];
int[] arrT = new int[T];
for (int t = 0; t < T; t++){
arr[n+4000]++;
arrT[t] = n;
sum += n;
if (n > max)
max = n;
if (n < min)
min = n;
}
sb.append(getMean(sum, T)).append('\n');//산술평균
sb.append(getMedian(arrT, T)).append('\n');//중앙값
sb.append(getMode(arr, max, min)).append('\n');//최빈값
sb.append(getRange(max, min)).append('\n');//범위
System.out.println(sb);
br.close();
}

static int getMean(int sum, int T){
return (int)Math.round((double)sum/T);
}
static int getMedian(int[] arr, int T){
Arrays.sort(arr);
return arr[T/2];
}
static int getMode(int[] arr, int max, int min){
Boolean flag = null;
int mode = 0, modeMax = 0;
for(int a = min + 4000; a <= max + 4000; a++){
if (arr[a] > mode){
mode = arr[a];
modeMax = a - 4000;
flag = true;
} else if (arr[a] == mode && flag) {
modeMax = a - 4000;
flag = false;
}
}
return  modeMax;
}
static int getRange(int max, int min){
return max - min;
}
}