본문 바로가기
Algorithm/BaekJoon[Java]

백준 10818

by 씨니 2022. 3. 17.
728x90

 

▶풀이방법1

import java.util.*;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int num = sc.nextInt();
		int nums[] = new int[num];
		
		for(int i = 0; i < num; i++) {
			nums[i] = sc.nextInt();
		}
		
		Arrays.sort(nums);
		System.out.print(nums[0] + " " + nums[num-1]);
	}
}

 

▶풀이방법2

import java.util.*;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int num = sc.nextInt();
		int Max = -1000000;
		int Min = 1000000;
		
		for(int i = 0; i < num; i++) {
			int number = sc.nextInt();
			Max = Math.max(Max, number);
			Min = Math.min(Min, number);
		}
		
		System.out.println(Min + " " + Max);
	}
}
728x90

'Algorithm > BaekJoon[Java]' 카테고리의 다른 글

백준 10991, 10992 (별찍기)  (0) 2022.03.18
백준 2438, 2439, 2440, 2441, 2442, 2445, 2446 (별찍기)  (0) 2022.03.17
백준 8393  (0) 2022.03.17
백준 1924  (0) 2022.03.17
백준 2739  (0) 2022.03.16