문제

문제출처 : Baekjoon

img

풀이

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();

        int[] arr = new int[3];
        arr[0] = A;
        arr[1] = B;
        arr[2] = C;

        Arrays.sort(arr);

        int second = arr[1];

        System.out.println(second);
    }
}

회고

  1. 처음에는 if문으로 A,B,C에 max, min 설정하고 어쩌구 해서 다 비교하는걸 생각했었는데 sort 함수를 사용하면 좀 더 쉽게 사용할 수 있을것 같아서 이렇게 해결했다. 이것보다 더 간단하게 푸는 방법도 있겠지만 현재의 내 최선은 이 방법인것같다.