-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaxMinValue.java
More file actions
36 lines (32 loc) · 983 Bytes
/
Copy pathMaxMinValue.java
File metadata and controls
36 lines (32 loc) · 983 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
31
32
33
34
35
36
package level2;
import java.util.Arrays;
public class MaxMinValue {
public static void main(String[] args) {
SolutionMaxMinValue su = new SolutionMaxMinValue();
String s = "1 2 3 4"; // 1 4
// String s = "-1 -2 -3 -4"; // -4 -1
// String s = "-1 1"; // -1 1
System.out.println(su.solution(s));
}
}
class SolutionMaxMinValue {
public String solution(String s) {
StringBuffer sb = new StringBuffer();
String[] num = s.split(" ");
int[] nums = new int[num.length];
for(int i=0; i<nums.length; i++) {
nums[i] = Integer.parseInt(num[i]);
}
Arrays.sort(nums);
sb.append(nums[0]);
sb.append(" ");
sb.append(nums[nums.length-1]);
return sb.toString();
/* 22번째부터 다른 코드
* sb.append(Arrays.stream(nums).min().getAsInt());
* sb.append(" ");
* sb.append(Arrays.stream(nums).max().getAsInt());
* return sb.toString();
*/
}
}