BOJ 10818 문제
https://www.acmicpc.net/problem/10818
Scanner
package boj;
import java.util.Arrays;
import java.util.Scanner;
public class Boj_10818_Scanner {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
int[] arr = new int[N];
int min = Integer.MAX_VALUE;
int max = 0;
for(int i=0; i<N; i++) {
arr[i]=scan.nextInt();
}
Arrays.sort(arr);
System.out.println(arr[0]+" "+arr[N-1]);
}
}
BufferedReader
package boj;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Boj_10818_BufferedReader{
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine()," ");
int index=0;
int[] arr = new int[N];
while(st.hasMoreTokens()) {
arr[index] = Integer.parseInt(st.nextToken());
index++;
}
Arrays.sort(arr);
System.out.println(arr[0]+" "+arr[N-1]);
}
}
속도, 메모리면에서 BufferedReader가 훨씬 효율이 좋다.
scanner
BufferedReader
단점은 코드길이가 길어진다는 것
'언어 > JAVA' 카테고리의 다른 글
백준 2252 - 줄세우기(위상정렬) (0) | 2021.07.24 |
---|---|
JAVA 최대공약수 구하기 (0) | 2021.07.23 |
Constructor 생성자 (0) | 2021.05.29 |
Method Overloading (0) | 2021.05.29 |
Setters, Getters (0) | 2021.05.26 |
댓글