Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. import java.util.*;
  2. public class Books implements Comparable {
  3. int id;
  4. int score;
  5. public Books(int id, int score) {
  6. this.id = id;
  7. this.score = score;
  8. }
  9. @Override public String toString() {
  10. return "Books [id=" + id + ", score=" + score + "]";
  11. }
  12. public int compareTo(Books that) {
  13. return (that.score - this.score);
  14. }
  15. public static void arrange_books(String S, TreeSet orderedBooks) {
  16. String[] score = S.split(" ");
  17. int i = 0;
  18. for (String s: score) {
  19. Books b = new Books(i, Integer.parseInt(s));
  20. orderedBooks.add(b);
  21. i++;
  22. }
  23. for (Books x: orderedBooks) System.out.println(x.toString());
  24. }
  25. public static void main(String[] args) { // TODO Auto-generated method stub TreeSet myList=new TreeSet(); arrange_books("1 2 3 6 5 4",myList);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement