-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListOfPredicate.java
More file actions
29 lines (26 loc) · 951 Bytes
/
Copy pathListOfPredicate.java
File metadata and controls
29 lines (26 loc) · 951 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
package Exercises;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.function.BiFunction;
import java.util.stream.Collectors;
public class ListOfPredicate {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = Integer.parseInt(scan.nextLine());
List<Integer> list = Arrays.stream(scan.nextLine().split("\\s+")).map(e -> Integer.parseInt(e)).collect(Collectors.toList());
BiFunction<Integer, List<Integer>, Boolean> isDivisible = ((number, input) -> {
for (int numberInList : input) {
if (number % numberInList != 0) {
return false;
}
}
return true;
});
for (int i = 1; i <=n ; i++) {
if(isDivisible.apply(i,list)){
System.out.print(i + " ");
}
}
}
}