-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ6.java
47 lines (44 loc) · 1.63 KB
/
Q6.java
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
37
38
39
40
41
42
43
44
45
46
47
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.stream.Collectors;
public class Q6 {
public static void main(String[] args) throws Exception {
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
String inp = read.readLine();
int[] minint=Arrays.stream(inp.substring(0, inp.length()).split(","))
.map(String::trim).mapToInt(Integer::parseInt).toArray();
Integer[] maxint =Arrays.stream(minint).boxed().toArray(Integer[]::new);
Arrays.sort(minint);
String[] min=Arrays.stream(minint)
.mapToObj(String::valueOf)
.toArray(String[]::new);
Arrays.sort(maxint,cmp);
String[] max=Arrays.stream(maxint)
.map(String::valueOf)
.toArray(String[]::new);
String minstr = Arrays.stream(min).collect(Collectors.joining());
String maxstr = Arrays.stream(max).collect(Collectors.joining());
int minnum=Integer.valueOf(minstr);
int maxnum=Integer.valueOf(maxstr);
int dif=maxnum-minnum;
System.out.println("最大與最小相差"+dif);
System.out.println(minstr);
System.out.println(maxstr);
/*
int minnum=Integer.valueOf(min);
int maxnum=Integer.valueOf(max);
int dif=maxnum-minnum;
System.out.println("最大與最小相差"+dif);
*/
}
static Comparator<Integer> cmp= new Comparator<Integer>()
{
public int compare(Integer a, Integer b){
return b-a;
}
};
}