[백준/Java] 10818 : 최소, 최대

SEOP·2023년 6월 2일
0
post-custom-banner

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        int N = Integer.parseInt( br.readLine() );
        String[] STR = br.readLine().split(" ");

        List<Integer> list = new ArrayList<>();

        for(String str : STR){
            list.add( Integer.parseInt(str));
        }

        int min = list.get(0);
        int max = list.get(0);

        for(int i = 1; i<list.size();i++){
            if(min>list.get(i)){
                min = list.get(i);
            }
            if(max<list.get(i)){
                max = list.get(i);
            }
        }

        bw.write(min + " " + max);
        bw.flush();
        bw.close();
    }
}
profile
응애 나 애기 개발자
post-custom-banner

0개의 댓글