Hello Programmers/Coders, Today we are going to share solutions of Programming problems of HackerRank of Programming Language Java . At Each Problem with Successful submission with all Test Cases Passed, you will get an score or marks. And after solving maximum problems, you will be getting stars. This will highlight your profile to the recruiters.
In this post, you will find the solution for Java Lambda Expressions-HackerRank Problem. We are providing the correct and tested solutions of coding problems present on HackerRank. If you are not able to solve any problem, then you can take help from our Blog/website.
Use “Ctrl+F” To Find Any Questions Answer. & For Mobile User, You Just Need To Click On Three dots In Your Browser & You Will Get A “Find” Option There. Use These Option to Get Any Random Questions Answer.
Introduction To Java
JAVA was developed by James Gosling at Sun Microsystems Inc in the year 1991, later acquired by Oracle Corporation. It is a simple programming language. Java makes writing, compiling, and debugging programming easy. It helps to create reusable code and modular programs.
Java is a class-based, object-oriented programming language and is designed to have as few implementation dependencies as possible. A general-purpose programming language made for developers to write once run anywhere that is compiled Java code can run on all platforms that support Java. Java applications are compiled to byte code that can run on any Java Virtual Machine. The syntax of Java is similar to c/c++.
Link for the Problem – Java Lambda Expressions – Hacker Rank Solution
Java Lambda Expressions – Hacker Rank Solution
This Java 8 challenge tests your knowledge of Lambda expressions!
Write the following methods that return a lambda expression performing a specified action:
- PerformOperation isOdd(): The lambda expression must return if a number is odd or if it is even.
- PerformOperation isPrime(): The lambda expression must return if a number is prime or if it is composite.
- PerformOperation isPalindrome(): The lambda expression must return if a number is a palindrome or if it is not.
Input Format
Input is handled for you by the locked stub code in your editor.
Output Format
The locked stub code in your editor will print lines of output.
Sample Input
The first line contains an integer, (the number of test cases).
The subsequent lines each describe a test case in the form of space-separated integers:
The first integer specifies the condition to check for ( for Odd/Even, for Prime, or for Palindrome). The second integer denotes the number to be checked.
5 1 4 2 5 3 898 1 3 2 12
Sample Output
EVEN PRIME PALINDROME ODD COMPOSITE
Java Lambda Expressions – Hacker Rank Solution
import java.io.*; import java.util.*; interface PerformOperation { boolean check(int a); } class MyMath { public static boolean checker(PerformOperation p, int num) { return p.check(num); } PerformOperation isOdd() { PerformOperation po = (int a)-> a%2 == 0 ? false : true; return po; } PerformOperation isPrime() { PerformOperation po = (int a)-> { if(a == 1) return true; else { for (int i = 2; i < Math.sqrt(a); i++) if(a%i == 0) return false; return true; } }; return po; } PerformOperation isPalindrome() { ArrayList<Integer> aa = new ArrayList<>(); PerformOperation po = (int a)-> { String str = Integer.toString(a); String reverse = ""; for(int i = str.length()-1; i >= 0; i--) { reverse = reverse + str.charAt(i); } if(reverse.equals(str)) return true; return false; }; return po; } } public class Solution { public static void main(String[] args) throws IOException { MyMath ob = new MyMath(); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int T = Integer.parseInt(br.readLine()); PerformOperation op; boolean ret = false; String ans = null; while (T--> 0) { String s = br.readLine().trim(); StringTokenizer st = new StringTokenizer(s); int ch = Integer.parseInt(st.nextToken()); int num = Integer.parseInt(st.nextToken()); if (ch == 1) { op = ob.isOdd(); ret = ob.checker(op, num); ans = (ret) ? "ODD" : "EVEN"; } else if (ch == 2) { op = ob.isPrime(); ret = ob.checker(op, num); ans = (ret) ? "PRIME" : "COMPOSITE"; } else if (ch == 3) { op = ob.isPalindrome(); ret = ob.checker(op, num); ans = (ret) ? "PALINDROME" : "NOT PALINDROME"; } System.out.println(ans); } } }
Its ⅼike you read my mind! You appear to know so much about this, liҝe you ᴡrοte thе
boօk in іt or something. I think that уou can do ѡith a few pics
to drive the message home a bit, but instead of that, this is great blog.
A fantastic reaԁ. Ι’ll certainly be back.
Hi there, just became alert to your blog through Google, and found that it is truly informative. I’m going to watch out for brussels. I will be grateful if you continue this in future. A lot of people will be benefited from your writing. Cheers!
Wohh just what I was searching for, regards for posting.
Hi my loved one! I wish to say that this article is awesome, nice written and come with almost all important infos. I would like to peer extra posts like this .
I simply couldn’t leave your site prior to suggesting that I extremely loved the usual information a person supply to your guests? Is gonna be back regularly to check out new posts
We stumbled over here from a different web address and thought I might check things out. I like what I see so now i am following you. Look forward to checking out your web page again.
Hiya very cool blog!! Man .. Beautiful .. Wonderful .. I will bookmark your site and take the feeds also?KI am satisfied to search out numerous helpful info here in the publish, we need develop more strategies in this regard, thanks for sharing. . . . . .
We’re a gaggle of volunteers and opening a brand new scheme in our community. Your web site offered us with useful info to paintings on. You’ve performed an impressive job and our whole neighborhood shall be grateful to you.
It?¦s really a cool and helpful piece of information. I am satisfied that you just shared this useful info with us. Please stay us informed like this. Thanks for sharing.
Hi there, I found your blog via Google while looking for a related topic, your website came up, it looks great. I’ve bookmarked it in my google bookmarks.
Thanx for the effort, keep up the good work Great work, I am going to start a small Blog Engine course work using your site I hope you enjoy blogging with the popular BlogEngine.net.Thethoughts you express are really awesome. Hope you will right some more posts.
I appreciate, cause I found just what I was looking for. You’ve ended my 4 day long hunt! God Bless you man. Have a great day. Bye
I got what you intend, appreciate it for putting up.Woh I am happy to find this website through google. “The test and use of a man’s education is that he finds pleasure in the exercise of his mind.” by Carl Barzun.
After I initially commented I clicked the -Notify me when new comments are added- checkbox and now every time a comment is added I get 4 emails with the identical comment. Is there any means you may remove me from that service? Thanks!
Hi there very nice website!! Man .. Excellent .. Wonderful .. I will bookmark your site and take the feeds additionallyKI am satisfied to search out numerous useful info here in the put up, we need develop more techniques in this regard, thanks for sharing. . . . . .
It’s hard to find knowledgeable people on this subject, but you sound like you already know what you’re talking about! Thanks
I would like to thnkx for the efforts you’ve put in writing this website. I am hoping the same high-grade web site post from you in the upcoming as well. Actually your creative writing abilities has encouraged me to get my own blog now. Actually the blogging is spreading its wings rapidly. Your write up is a great example of it.
I’m not that much of a internet reader to be honest but your sites really nice, keep it up! I’ll go ahead and bookmark your site to come back later on. Cheers
Very interesting information!Perfect just what I was looking for!
Youre so cool! I dont suppose Ive read something like this before. So good to seek out somebody with some unique ideas on this subject. realy thank you for starting this up. this website is one thing that is needed on the internet, somebody with a bit originality. useful job for bringing something new to the internet!
brand tadalafil tadalafil 10mg price best erection pills
Nice post. I was checking continuously this blog and I am impressed! Very helpful information specifically the last part 🙂 I care for such information much. I was seeking this particular information for a long time. Thank you and best of luck.
cheap cefadroxil lamivudine price order finasteride 5mg generic
buy estrace 2mg generic prazosin brand buy prazosin 1mg online
diflucan 200mg pills buy cipro 1000mg online cheap oral ciprofloxacin
buy mebendazole 100mg online buy tadalis 20mg generic buy generic tadalafil 20mg
order metronidazole for sale bactrim 480mg generic buy cephalexin 500mg pills
order generic avanafil order diclofenac 100mg generic cost diclofenac
buy clindamycin paypal buy ed medications online generic fildena 50mg
indocin 50mg cost terbinafine for sale cefixime 200mg ca
tamoxifen 10mg pills order ceftin without prescription ceftin without prescription
order trimox generic order generic biaxin 500mg order biaxin 500mg pill
order catapres 0.1mg without prescription cost tiotropium bromide how to buy spiriva
bimatoprost buy online purchase desyrel online trazodone 100mg ca
how to get minocycline without a prescription buy generic minomycin buy actos paypal
suhagra ca sildenafil 100mg sale sildalis cheap
order arava 20mg pills viagra pills 50mg sulfasalazine usa
absorica buy online zithromax 250mg brand brand zithromax 500mg
female cialis oral tadalafil 10mg order cialis 10mg online
buy generic azipro 250mg buy generic azithromycin 250mg buy neurontin 800mg pills
stromectol south africa stromectol for people buy deltasone 40mg generic
generic furosemide 40mg furosemide over the counter ventolin inhalator ca
levitra drug buy generic levitra brand hydroxychloroquine
I’ll right away grasp your rss feed as I can not find your e-mail subscription link or newsletter service. Do you have any? Please let me recognise so that I may subscribe. Thanks.
levitra 10mg brand buy levitra 10mg for sale order hydroxychloroquine 200mg sale
I’m no longer sure where you are getting your info, however good topic. I must spend a while learning much more or figuring out more. Thanks for magnificent info I used to be in search of this info for my mission.