백준 20053번 : 최소, 최대 2 | 자바 풀이

박지윤·2022년 7월 16일
0

Algorithm_Implementation

목록 보기
9/16

[ Solution ]

import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args) throws IOException {

        Scanner sc = new Scanner(System.in);
        int test_n = sc.nextInt();

        for(int i = 1; i <= test_n; i++) {
            int num = sc.nextInt();
            int max = Integer.MIN_VALUE;
            int min = Integer.MAX_VALUE;

            for(int j = 0; j < num; j++) {
                int compare = sc.nextInt();
                if(compare > max) max = compare;
                if(compare < min) min = compare;
            }
            System.out.println(min + " " + max);
        }
    }
}

각 테스트 케이스마다 max 값과 min 값을 입력값과 비교하여 갱신해주고, 최종적으로 결정된 max 값과 min 값을 출력해주면 된다.

0개의 댓글