-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPrincipale.java
More file actions
75 lines (56 loc) · 1.41 KB
/
Copy pathPrincipale.java
File metadata and controls
75 lines (56 loc) · 1.41 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package smallInterval;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.NoSuchElementException;
public class Principale {
public static void main(String[] args) {
List<Integer> tableau = new ArrayList<Integer>();
tableau.add(1);
tableau.add(5);
tableau.add(7);
tableau.add(9);
List<Interval> interval = new ArrayList<Interval>();
for(int i=0;i<tableau.size()-1;i++) {
interval.add(new Interval(tableau.get(i), tableau.get(i+1), tableau.get(i+1)-tableau.get(i)));
}
Interval minDiff = interval
.stream()
.min(Comparator.comparing(Interval::getDiff))
.orElseThrow(NoSuchElementException::new);
System.out.println(minDiff);
}
}
class Interval {
int rangeMin;
int rangeMax;
int diff;
public Interval(int rangeMin, int rangeMax, int diff) {
super();
this.rangeMin = rangeMin;
this.rangeMax = rangeMax;
this.diff = diff;
}
public int getRangeMin() {
return rangeMin;
}
public void setRangeMin(int rangeMin) {
this.rangeMin = rangeMin;
}
public int getRangeMax() {
return rangeMax;
}
public void setRangeMax(int rangeMax) {
this.rangeMax = rangeMax;
}
public int getDiff() {
return diff;
}
public void setDiff(int diff) {
this.diff = diff;
}
@Override
public String toString() {
return "Interval [rangeMin=" + rangeMin + ", rangeMax=" + rangeMax + ", diff=" + diff + "]";
}
}