문제
내 코드
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
StringTokenizer sz = new StringTokenizer(br.readLine());
int num;
int min = 1000001;
int max = -1000001;
while (sz.hasMoreTokens()) {
num = Integer.parseInt(sz.nextToken());
if (min > num) min = num;
if (max < num) max = num;
}
System.out.printf("%d %d", min, max);
}
}
1. 사용할 변수들 생성
int num;
int min = 1000001;
int max = -1000001;
2. min, max 찾기
while (sz.hasMoreTokens()) {
num = Integer.parseInt(sz.nextToken());
if (min > num) min = num;
if (max < num) max = num;
}