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.
My solution:
public static PerformOperation is_odd() {
return n -> n % 2 != 0;
}
public PerformOperation is_prime() {
return n -> !java.util.stream.IntStream.rangeClosed(2, (int)java.lang.Math.sqrt(n)).anyMatch(x -> n % x == 0);
}
public PerformOperation is_palindrome() {
return n -> {
String s = String.valueOf(n);
int len = s.length();
return java.util.stream.IntStream.rangeClosed(1, (int)len/2).anyMatch(p -> s.charAt(p-1) == s.charAt(len - p));
} ;
}
}
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 →
My solution: public static PerformOperation is_odd() { return n -> n % 2 != 0; }
}