Advertisement
iamaamir

Functional java

Jul 28th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. import java.util.function.IntPredicate;
  2. import java.util.stream.IntStream;
  3.  
  4. /**
  5.  *
  6.  * @author toffe boy Aamir
  7.  */
  8. public class Funktional {
  9.  
  10.     private static boolean isPrime(final int number) {
  11.         IntPredicate isDivisible = divisor -> number % divisor == 0;//function in a function (Believe it or not)
  12.        
  13.         return number > 1 &&
  14.                 IntStream.range(2, number).
  15.                 noneMatch(isDivisible::test);
  16.     }
  17.  
  18.     public static void main(String[] args) {
  19.         System.out.println(isPrime(1));
  20.         System.out.println(isPrime(2));
  21.         System.out.println(isPrime(3));
  22.         System.out.println(isPrime(4));
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement