forked from sahilbansalweb/Hacktoberfest2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionInterface.java
More file actions
36 lines (35 loc) · 886 Bytes
/
FunctionInterface.java
File metadata and controls
36 lines (35 loc) · 886 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
30
31
32
33
34
35
36
import java.util.function.Function;
public class FunctionInterface {
public static void main(String args[]) {
Function<Integer,Boolean> findPrime = (x) -> {
if(x <= 1){
return false;
}
if(x==2 || x==3){
return true;
}
if(x%2 == 0){
return false;
}
for(int i=3;i<=Math.sqrt(x);i+=2){
if(x%i == 0){
return false;
}
}
return true;
};
System.out.println(findPrime.apply(3));
System.out.println(findPrime.apply(7));
System.out.println(findPrime.apply(11));
System.out.println(findPrime.apply(19));
System.out.println(findPrime.apply(21));
System.out.println(findPrime.apply(53));
}
}
//OUTPUT OF PROGRAM IS
// true
// true
// true
// true
// false
// true