Sort by

recency

|

269 Discussions

|

  • + 0 comments
    // Write your Checker class here
    class Checker implements Comparator<Player> {
        public int compare(Player a, Player b) {
            if (a.score != b.score) {
               return b.score - a.score; 
            }
            else {
                return a.name.compareTo(b.name);
            }
        }
    }
    
  • + 0 comments

    /* *@Author : Rehan */ public int compare(Player a, Player b){ int scoreCompare = b.score - a.score; int nameCompare = a.name.compareTo(b.name); if(scoreCompare==0) { return nameCompare; }else{ return scoreCompare; } }

  • + 0 comments

    class Checker implements Comparator { public int compare(Player p1, Player p2) { int scoreComparator = Integer.compare(p2.score, p1.score); if (scoreComparator != 0) { return scoreComparator; } else { return p1.name.compareTo(p2.name); } } }

  • + 0 comments

    class Checker implements Comparator{

    @Override
    public int compare(Player p1, Player p2){
        int scoreCompare = p2.score - p1.score; 
        int nameCompare = p1.name.compareTo(p2.name);
        return (scoreCompare==0) ? nameCompare:scoreCompare; 
    }
    

    }

  • + 0 comments
    class Checker implements Comparator<Player> {
        public int compare(Player p1, Player p2) {
            int scoreComparator = Integer.compare(p2.score, p1.score);
            if (scoreComparator != 0) {
                return scoreComparator;
            } else {
                return p1.name.compareTo(p2.name);
            }
        }
    }