- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJavaLambdaExpression.java
More file actions
Latest commit
34 lines (29 loc) · 1007 Bytes
/
Copy pathJavaLambdaExpression.java
File metadata and controls
34 lines (29 loc) · 1007 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
// https://www.hackerrank.com/challenges/java-lambda-expressions/problem
publicclassJavaLambdaExpression {
privateinterfacePerformOperation {
booleancheck(intnumber);
}
privatestaticclassMyMath {
publicstaticPerformOperationisOdd() {
return (inta) -> a % 2 != 0;
}
publicstaticPerformOperationisPrime() {
return (intnumber) -> {
if(number == 1) returnfalse;
for (intindex = 2 ; index * index <= number ; index++) {
if (number % index == 0) {
returnfalse;
}
}
returntrue;
};
}
publicstaticPerformOperationisPalindrome() {
return (inta) -> {
Stringnumber = a + "";
Stringreverse = newStringBuilder(number).reverse().toString();
returnnumber.equals(reverse);
};
}
}
}