-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathLotto.java
34 lines (28 loc) · 825 Bytes
/
Lotto.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
/* Java 8 */
import java.util.Arrays;
import java.util.Random;
import java.util.stream.Collectors;
public class Main {
public static void main(String[] args) {
Lotto lotto = new Lotto();
lotto.print();
}
}
public class Lotto {
private Integer[] generate() {
return new Random().ints(1, 46)
.distinct()
.limit(6)
.boxed()
.sorted()
.toArray(Integer[]::new);
}
private String format(Integer[] numbers) {
return Arrays.stream(numbers)
.map(number -> number.toString())
.collect(Collectors.joining(", "));
}
public void print() {
System.out.println(format(generate()));
}
}