Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.function.IntPredicate;
- import java.util.stream.IntStream;
- /**
- *
- * @author toffe boy Aamir
- */
- public class Funktional {
- private static boolean isPrime(final int number) {
- IntPredicate isDivisible = divisor -> number % divisor == 0;//function in a function (Believe it or not)
- return number > 1 &&
- IntStream.range(2, number).
- noneMatch(isDivisible::test);
- }
- public static void main(String[] args) {
- System.out.println(isPrime(1));
- System.out.println(isPrime(2));
- System.out.println(isPrime(3));
- System.out.println(isPrime(4));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement