We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static PerformOperation isOdd() {
return (num) -> num%2!=0;
}
public static PerformOperation isPrime() {
return (num) -> java.math.BigInteger.valueOf(num).isProbablePrime(100);
}
public static PerformOperation isPalindrome() {
return num -> num == reverseNum(num);
}
private static int reverseNum(int num) {
int result = 0;
while(num > 0) {
int val = num%10;
result = (result * 10) + val;
num = num/10;
}
return result;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Lambda Expressions
You are viewing a single comment's thread. Return to all comments →
public static PerformOperation isOdd() { return (num) -> num%2!=0; }
public static PerformOperation isPrime() { return (num) -> java.math.BigInteger.valueOf(num).isProbablePrime(100); }
public static PerformOperation isPalindrome() { return num -> num == reverseNum(num); }
private static int reverseNum(int num) { int result = 0; while(num > 0) { int val = num%10; result = (result * 10) + val; num = num/10; } return result; }