본문 바로가기

알고리즘/Java

(JAVA) 백준 알고리즘 6단계 10818번 : 최소, 최대

배열

 

 

소스

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
    
        Scanner scan = new Scanner(System.in);
        
        int a = scan.nextInt();
        int[] arr = new int[a];
        
        for (int i = 0; i < a; i++) {
            arr[i] = scan.nextInt();
        }
        scan.close();
        Arrays.sort(arr);
        System.out.print(arr[0+ " " + arr[a - 1]);
    }
}
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
cs

 

Arrays.sort 는 배열을 오름차순으로 정렬시켜주는 메소드

(참고 : https://st-lab.tistory.com/43)

 

[백준] 10818번 : 최소, 최대 - JAVA [자바]

https://www.acmicpc.net/problem/10818 10818번: 최소, 최대 첫째 줄에 정수의 개수 N (1 ≤ N ≤ 1,000,000)이 주어진다. 둘째 줄에는 N개의 정수를 공백으로 구분해서 주어진다. 모든 정수는 -1,000,000보..

st-lab.tistory.com