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.
- Practice
- Java
- Advanced
- Java Lambda Expressions
- Discussions
Java Lambda Expressions
Java Lambda Expressions
manni_reies + 0 comments Trying to keep everything to one line. Might not be the most efficient, but it's clean.
public static PerformOperation is_odd(){ return (int a) -> a % 2 != 0; } public static PerformOperation is_prime(){ return (int a) -> java.math.BigInteger.valueOf(a).isProbablePrime(1); } public static PerformOperation is_palindrome(){ return (int a) -> Integer.toString(a).equals( new StringBuilder(Integer.toString(a)).reverse().toString() ); }
ozdemirburak + 0 comments public PerformOperation is_odd(){ return n -> (n%2 != 0); } public PerformOperation is_prime(){ return n -> IntStream.range(2, (int) Math.sqrt(n+1)) .noneMatch(i -> n%i == 0); } public PerformOperation is_palindrome(){ return n -> IntStream.iterate(n, e -> e/10 ) .limit(11) .filter(f -> f>0) .map(e -> e%10) .reduce(0, (c,e)->c*10+e) == n; }
niteshkrsingh51 + 0 comments Its a bit long but easy to understand...
public static PerformOperation isOdd() { return num -> { if(num%2==0) return false; else return true; } ; } public static PerformOperation isPrime() { return num -> { int flag = 0; for(int i=2;i<=num/2;i++) { if(num%i==0) { flag = 1; break; } else { flag = 0; break; } } if(flag == 0) return true; else return false; }; } public static PerformOperation isPalindrome() { return num -> { int r,sum=0,temp; temp = num; while(num>0) { r = num % 10; sum = (sum*10)+r; num = num/10; } if(temp == sum) return true; else return false; }; } }
morfanos + 0 comments I have so many issues with this exercise...
namespace clashing, e.g. class Math { }.
(a) Returning 0/1 instead of true/false.
(b) Returning 0 to denote a truthy value, which goes against common coding sense.
This:
op = ob.checkEvenOdd(); ret = ob.checker(op, num);
The whole thing was confusing from begining to end!
ajitpandit881 + 0 comments Solution.java:76: error: reached end of file while parsing } ^ 1 error
Getting this error because of missing closing bracket. Please fix this issue ASAP
Load more conversations
Sort 81 Discussions, By:
Please Login in order to post a comment