Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Books implements Comparable {
- int id;
- int score;
- public Books(int id, int score) {
- this.id = id;
- this.score = score;
- }
- @Override public String toString() {
- return "Books [id=" + id + ", score=" + score + "]";
- }
- public int compareTo(Books that) {
- return (that.score - this.score);
- }
- public static void arrange_books(String S, TreeSet orderedBooks) {
- String[] score = S.split(" ");
- int i = 0;
- for (String s: score) {
- Books b = new Books(i, Integer.parseInt(s));
- orderedBooks.add(b);
- i++;
- }
- for (Books x: orderedBooks) System.out.println(x.toString());
- }
- public static void main(String[] args) { // TODO Auto-generated method stub TreeSet myList=new TreeSet(); arrange_books("1 2 3 6 5 4",myList);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement