-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinMax.java
More file actions
30 lines (27 loc) · 781 Bytes
/
Copy pathMinMax.java
File metadata and controls
30 lines (27 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.util.Scanner;
public class MinMax {
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
int n = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
System.out.println(getMin(arr, n) + " " + getMax(arr, n));
}
}
public static int getMin(int[] arr, int n) {
int res = arr[0];
for (int i = 0; i < n; i++) {
res = Math.min(arr[i], res);
}
return res;
}
public static int getMax(int[] arr, int n) {
int res = arr[0];
for (int i = 0; i < n; i++) {
res = Math.max(arr[i], res);
}
return res;
}
}