끄적끄적 코딩
article thumbnail
Published 2023. 1. 12. 21:09
[Java] SWEA - 중간값 찾기 알고리즘
728x90

배열에 넣어서 정렬을 하고 가운데 값을 출력해주었습니다.

import java.util.*;
import java.io.FileInputStream;
 
class Solution
{
    public static void main(String args[]) throws Exception
    {       
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
        int [] arr = new int[n];
        for(int i=0; i<n; ++i){
            arr[i] = sc.nextInt();
        }
        Arrays.sort(arr);
        System.out.printf("%d", arr[n/2]);
    }
}

 

 

'알고리즘' 카테고리의 다른 글

[Java] SWEA - 1대1 가위바위보  (0) 2023.01.12
[Java] SWEA - 자릿수 더하기  (0) 2023.01.12
[Java] SWEA - 최대수 구하기  (0) 2023.01.12
[Java] SWEA - 두 개의 숫자열  (0) 2023.01.12
[Java] SWEA - Sum  (0) 2023.01.12

검색 태그