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.
public Details(int id,String name,double point){
this.id = id;
this.name = name;
this.point = point;
}
public String getName(){
return name;
}
public int getId(){
return id;
}
public double getPoint(){
return point;
}
}
public class Main {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner persons = new Scanner(System.in);
int numberOfPersons = persons.nextInt();
List<Details> students = new ArrayList<>();
for(int i=0;i<numberOfPersons;i++){
int id = persons.nextInt();
String name = persons.next();
double point = persons.nextDouble();
students.add(new Details(id, name, point));
}
persons.close();
List<Details> answer = students.stream().sorted(Comparator.comparingDouble(Details::getPoint).reversed().thenComparing(Details::getName).thenComparingInt(Details::getId)).collect(Collectors.toList());
answer.forEach(student->System.out.println(student.name));
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Java Sort
You are viewing a single comment's thread. Return to all comments →
import java.io.; import java.util.; import java.util.stream.Collectors;
class Details{ int id; String name; double point;
}
public class Main {
}