Baekjoon Algorithm | Problem 10818: Minimum, Maximum
Source
https://www.acmicpc.net/problem/10818
Problem
Solve Baekjoon Online Judge problem 10818, Minimum, Maximum.
Input
Follow the input format and constraints given in the original problem statement.
Output
Print the answer required by the problem.
Sample Input 1
5 20 10 35 30 7
Sample Output 1
7 35
Algorithm Classification
- Math
- Implementation
Solution
import java.io.*;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
int n = Integer.parseInt(br.readLine());
StringTokenizer nums = new StringTokenizer(br.readLine(), " ");
int a = Integer.parseInt(nums.nextToken());
int min = a;
int max = a;
for (int i = 1; i < n; i++) {
a = Integer.parseInt(nums.nextToken());
if (a > max) {
max = a;
} else if (a < min) {
min = a;
}
}
System.out.println(min + " " + max);
}
}
}