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
  • Certification
  • Compete
  • Career Fair
  • Hiring developers?
  1. Practice
  2. Java
  3. Advanced
  4. Java Lambda Expressions
  5. Discussions

Java Lambda Expressions

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 81 Discussions, By:

votes

Please Login in order to post a comment

  • manni_reies 4 years ago+ 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() );
        }
    
    86|
    Permalink
  • ozdemirburak 4 years ago+ 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;
     }
    
    27|
    Permalink
  • niteshkrsingh51 3 years ago+ 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;
        };
       
    }
    }
    
    17|
    Permalink
  • morfanos 5 years ago+ 0 comments

    I have so many issues with this exercise...

    1. namespace clashing, e.g. class Math { }.

    2. (a) Returning 0/1 instead of true/false.

    3. (b) Returning 0 to denote a truthy value, which goes against common coding sense.

    4. This:

      op = ob.checkEvenOdd(); ret = ob.checker(op, num);

    The whole thing was confusing from begining to end!

    11|
    Permalink
  • ajitpandit881 2 years ago+ 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

    8|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature