Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
svetlanasieber authored May 28, 2024
1 parent 25f8a86 commit 2e27f84
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import java.util.Arrays;
import java.util.Scanner;
import java.util.function.IntPredicate;
import java.util.function.Predicate;
import java.util.stream.IntStream;

public class O9_ListOfPredicates {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

int n = Integer.parseInt(scanner.nextLine());
int[] numbersToDivide = Arrays.stream(scanner.nextLine().split("\\s+"))
.mapToInt(Integer::parseInt)
.toArray();

IntPredicate isDivisible = num -> {
for (int i : numbersToDivide) {
if (num % i != 0) {
return false;
}
}

return true;
};

IntStream.rangeClosed(1, n)
.filter(isDivisible)
.forEach(num -> System.out.print(num + " "));
}
}

0 comments on commit 2e27f84

Please sign in to comment.