Sort by

recency

|

268 Discussions

|

  • + 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);
            }
        }
    }
    
  • + 0 comments
    public int compare(Player playerA, Player playerB) {
    
            if(playerB.score == playerA.score) {
                return playerA.name.compareTo(playerB.name);
            } else if (playerB.score > playerA.score) {
                return 1;
            } else {
                return -1;
            }
        }