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 Instanceof keyword-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 Instanceof keyword – Hacker Rank Solution
Java Instanceof keyword – Hacker Rank Solution
Problem :
The Java instanceof operator is used to test if the object or instance is an instanceof the specified type.
In this problem we have given you three classes in the editor:
- Student class
- Rockstar class
- Hacker class
In the main method, we populated an ArrayList with several instances of these classes. count method calculates how many instances of each type is present in the ArrayList. The code prints three integers, the number of instance of Student class, the number of instance of Rockstar class, the number of instance of Hacker class.
But some lines of the code are missing, and you have to fix it by modifying only lines! Don’t add, delete or modify any extra line.
To restore the original code in the editor, click on the top left icon in the editor and create a new buffer.
Sample Input
5 Student Student Rockstar Student Hacker
Sample Output
3 1 1
Java Instanceof keyword – Hacker Rank Solution
import java.util.*; class Student{} class Rockstar{ } class Hacker{} public class InstanceOFTutorial{ static String count(ArrayList mylist){ int a = 0,b = 0,c = 0; for(int i = 0; i < mylist.size(); i++){ Object element=mylist.get(i); if(element instanceof Student) a++; if(element instanceof Rockstar) b++; if(element instanceof Hacker) c++; } String ret = Integer.toString(a)+" "+ Integer.toString(b)+" "+ Integer.toString(c); return ret; } public static void main(String []args){ ArrayList mylist = new ArrayList(); Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int i=0; i<t; i++){ String s=sc.next(); if(s.equals("Student"))mylist.add(new Student()); if(s.equals("Rockstar"))mylist.add(new Rockstar()); if(s.equals("Hacker"))mylist.add(new Hacker()); } System.out.println(count(mylist)); } }
I not to mention my buddies were following the excellent tips and tricks from your web site while instantly I got an awful suspicion I never expressed respect to the website owner for those strategies. All the boys appeared to be totally thrilled to read them and now have surely been making the most of them. I appreciate you for being considerably considerate and then for considering such amazing tips millions of individuals are really needing to understand about. My honest apologies for not expressing appreciation to sooner.
Some truly nice and useful info on this website , besides I believe the layout holds fantastic features.
I’ll immediately snatch your rss feed as I can’t in finding your email subscription link or newsletter service. Do you’ve any? Please let me realize in order that I could subscribe. Thanks.
This is very interesting, You’re a very skilled blogger.
I’ve joined your feed and look forward to seeking more of
your wonderful post. Also, I’ve shared your site in my social networks!
Some truly nice and useful info on this internet site, as well I believe the pattern has got superb features.
I feel this is among the so much important info for me. And i’m glad reading your article. However should remark on some general issues, The website style is perfect, the articles is really nice : D. Excellent activity, cheers
It is in reality a nice and useful piece of info. I’m glad that you just shared this helpful info with us. Please stay us informed like this. Thank you for sharing.
I discovered your blog site on google and check a few of your early posts. Continue to keep up the very good operate. I just additional up your RSS feed to my MSN News Reader. Seeking forward to reading more from you later on!…
Great website! I am loving it!! Will be back later to read some more. I am taking your feeds also
Hi! Someone in my Facebook group shared this site with us so I came to take a look. I’m definitely enjoying the information. I’m bookmarking and will be tweeting this to my followers! Excellent blog and fantastic design and style.
Thanks so much for providing individuals with an extremely marvellous possiblity to check tips from this site. It is usually so lovely plus full of a lot of fun for me personally and my office mates to visit the blog at the very least 3 times every week to see the new issues you have. And indeed, we are at all times happy with your attractive suggestions you give. Certain 3 facts on this page are in reality the best I have ever had.
Some truly quality content on this internet site, saved to favorites.
Great write-up, I’m normal visitor of one’s website, maintain up the excellent operate, and It is going to be a regular visitor for a lengthy time.
Way cool, some valid points! I appreciate you making this article available, the rest of the site is also high quality. Have a fun.
The next time I read a blog, I hope that it doesnt disappoint me as a lot as this one. I imply, I know it was my choice to read, however I truly thought youd have something fascinating to say. All I hear is a bunch of whining about something that you would fix should you werent too busy searching for attention.
We’re a group of volunteers and starting a new scheme in our community. Your web site provided us with valuable information to work on. You’ve done a formidable job and our whole community will be thankful to you.
I wanted to thank you for this great read!! I definitely enjoying every little bit of it I have you bookmarked to check out new stuff you post…
This is a very good tips especially to those new to blogosphere, brief and accurate information… Thanks for sharing this one. A must read article.
tadalafil 10mg for sale buy cialis 10mg buy ed pills online
Your home is valueble for me. Thanks!…
where to buy duricef without a prescription cheap cefadroxil 500mg how to buy propecia
buy fluconazole 100mg pill brand ciprofloxacin 500mg order ciprofloxacin generic
where to buy metronidazole without a prescription purchase septra online buy keflex 250mg generic
vermox 100mg tablet order tadalafil 10mg without prescription tadalafil 20mg pills
cleocin pills erythromycin buy online generic ed pills
avana ca avana 100mg canada voltaren sale
buy cheap nolvadex buy cefuroxime 250mg for sale cefuroxime order online
indomethacin order order cefixime 100mg without prescription buy generic cefixime 200mg
amoxicillin drug buy clarithromycin 250mg without prescription buy biaxin 500mg pills
careprost order online order bimatoprost online cheap desyrel 50mg
order catapres 0.1mg online cheap spiriva order buy spiriva sale
order minomycin online cheap order actos 30mg purchase actos online
buy absorica pills isotretinoin 10mg brand azithromycin online
brand leflunomide purchase sildenafil pill order sulfasalazine 500mg online cheap
buy azipro generic azithromycin 250mg ca buy generic neurontin
furosemide 40mg uk furosemide sale albuterol 4mg cheap
ivermectin 6mg for people stromectol for humans for sale cheap deltasone 20mg
vardenafil tablet plaquenil 400mg over the counter plaquenil us
You are a very clever person!
order vardenafil 20mg pills purchase hydroxychloroquine buy hydroxychloroquine 200mg online
order benicar 20mg pill verapamil where to buy buy divalproex 250mg pill
buy generic coreg order cenforce 100mg online cheap chloroquine 250mg