https://www.acmicpc.net/problem/10818
10818번: 최소, 최대
첫째 줄에 정수의 개수 N (1 ≤ N ≤ 1,000,000)이 주어진다. 둘째 줄에는 N개의 정수를 공백으로 구분해서 주어진다. 모든 정수는 -1,000,000보다 크거나 같고, 1,000,000보다 작거나 같은 정수이다.
www.acmicpc.net
방법1
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
sc.nextLine();
for(int i=0; i<n; i++) {
arr[i] = sc.nextInt();
}
Arrays.sort(arr);
System.out.println(arr[0] + " " + arr[n-1]);
sc.close();
}
}
'알고리즘 > [백준] JAVA' 카테고리의 다른 글
[백준] 10813 공 바꾸기 (0) | 2023.04.28 |
---|---|
[백준] 2562 최댓값 (0) | 2023.04.28 |
[백준] 10807 개수 세기 (0) | 2023.04.25 |
[백준] 25304 영수증 (0) | 2023.04.24 |
[백준] 10950 A+B - 3 (0) | 2023.04.21 |