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

길 잃은 까마귀·2022년 9월 13일
0

https://www.acmicpc.net/problem/10818


  • 문제

  • 풀이
    쉬운 문제이다. N개의 수를 배열에 입력하고 이 배열을 arrays.sort라는 함수로 정렬해주면 크기순으로 정리가 되기 때문에 최솟값은 0에 위치한 값, 최댓값은 N-1에 위치한값인 것을 알 수 있다.

  • 코드
import java.util.*;

class Main {
	public static void main(String[] args) {
		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);
		sc.close();
		System.out.println(arr[0] + " " + arr[N - 1]);
	}
}
profile
코딩 고수가 될 사람

0개의 댓글