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 Sort-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 Sort- Hacker Rank Solution
Java Sort- Hacker Rank Solution
Problem :
You are given a list of student information: ID, FirstName, and CGPA. Your task is to rearrange them according to their CGPA in decreasing order. If two student have the same CGPA, then arrange them according to their first name in alphabetical order. If those two students also have the same first name, then order them according to their ID. No two students have the same ID.
Hint: You can use comparators to sort a list of objects. See the oracle docs to learn about comparators.
Input Format
The first line of input contains an integer , representing the total number of students. The next lines contains a list of student information in the following structure:
ID Name CGPA
Constraints
The name contains only lowercase English letters. The contains only integer numbers without leading zeros. The CGPA will contain, at most, 2 digits after the decimal point.
Output Format
After rearranging the students according to the above rules, print the first name of each student on a separate line
Sample Input
5 33 Rumpa 3.68 85 Ashis 3.85 56 Samiha 3.75 19 Samara 3.75 22 Fahim 3.76
Sample Output
Ashis Fahim Samara Samiha Rumpa
Java Sort- Hacker Rank Solution
import java.util.*; class Student { private int id; private String fname; private double cgpa; public Student(int id, String fname, double cgpa) { super(); this.id = id; this.fname = fname; this.cgpa = cgpa; } public int getId() { return id; } public String getFname() { return fname; } public double getCgpa() { return cgpa; } } public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); int testCases = Integer.parseInt(in.nextLine()); List<Student> studentList = new ArrayList<Student>(); while (testCases-- > 0) { int id = in.nextInt(); String fname = in.next(); double cgpa = in.nextDouble(); Student st = new Student(id, fname, cgpa); studentList.add(st); } Collections.sort(studentList, Comparator.comparing(Student::getCgpa).reversed(). thenComparing(Student::getFname).thenComparing(Student::getId)); for (Student st : studentList) { System.out.println(st.getFname()); } } }
Hiya! Quick question that’s totally off topic. Do you know how to make your site mobile friendly? My website looks weird when viewing from my iphone 4. I’m trying to find a template or plugin that might be able to fix this issue. If you have any recommendations, please share. Appreciate it!
I havenโt checked in here for some time because I thought it was getting boring, but the last few posts are great quality so I guess Iโll add you back to my daily bloglist. You deserve it my friend ๐
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!โฆ
It is really a nice and helpful piece of info. I am glad that you shared this helpful information with us. Please keep us informed like this. Thanks for sharing.
Now I am going away to do my breakfast, afterward having my breakfast coming again to read additional
news.
wonderful issues altogether, you simply won a new reader. What could you recommend about your post that you made some days ago? Any sure?
Itโs really a great and useful piece of information. Iโm glad that you shared this helpful information with us. Please keep us informed like this. Thanks for sharing.
F*ckinยฆ amazing things here. Iยฆm very satisfied to peer your article. Thanks a lot and i am looking ahead to touch you. Will you kindly drop me a mail?
Pretty! This was a really wonderful post. Thank you for your provided information.
Thank you for the auspicious writeup. It in fact was a amusement account it. Look advanced to far added agreeable from you! However, how could we communicate?
Some really superb articles on this web site, thanks for contribution. “Careful. We don’t want to learn from this.” by Bill Watterson.
I was reading some of your blog posts on this site and I believe this internet site is real informative! Keep posting.
Iโm not that much of a online reader to be honest but your blogs really nice, keep it up! I’ll go ahead and bookmark your website to come back in the future. Cheers
Real informative and fantastic body structure of subject matter, now that’s user friendly (:.
Wohh exactly what I was looking for, regards for posting.
Really clean site, thankyou for this post.
This really answered my problem, thanks!
Sweet web site, super style and design, rattling clean and use pleasant.
Hello would you mind sharing which blog platform you’re using? I’m planning to start my own blog soon but I’m having a hard time making a decision between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design seems different then most blogs and I’m looking for something unique. P.S My apologies for being off-topic but I had to ask!
order cialis for sale order cialis 10mg without prescription online ed medications
Hi , I do believe this is an excellent blog. I stumbled upon it on Yahoo , i will come back once again. Money and freedom is the best way to change, may you be rich and help other people.
I am curious to find out what blog platform you are working with? I’m experiencing some minor security issues with my latest site and I’d like to find something more safe. Do you have any recommendations?
buy duricef 500mg online order cefadroxil 500mg online cheap order generic proscar
estradiol 2mg over the counter buy lamictal 200mg generic minipress 2mg pill
order fluconazole 100mg pills buy ampicillin paypal cipro 500mg price
order mebendazole 100mg online cheap tadalis buy online tadalafil 20mg tablet
purchase metronidazole online cheap buy keflex 250mg pills generic keflex
brand avanafil 200mg buy tadacip sale diclofenac 50mg oral
indocin 50mg for sale terbinafine 250mg cheap order cefixime 200mg sale
trimox order online purchase arimidex online order clarithromycin 500mg for sale
buy clonidine for sale meclizine 25mg tablet spiriva 9mcg without prescription
how to buy careprost bimatoprost usa trazodone usa
purchase minocin for sale actos 30mg for sale buy pioglitazone without a prescription
buy cheap generic suhagra sildenafil cost sildenafil over the counter
buy generic arava over the counter azulfidine usa azulfidine buy online
tadalafil 40mg usa sildenafil drug cialis mail order us
ivermectin without a doctor prescription home remedies for ed erectile dysfunction buy prednisone 5mg online cheap
how to buy ramipril arcoxia generic purchase arcoxia generic