Java program to find the character that appears the most number of times in a String?

前端 未结 8 941
慢半拍i
慢半拍i 2020-12-22 13:03

So here\'s the code I\'ve got so far...

import java.util.Scanner;
class count{
    public static void main(String args[]){
        Scanner s=new Scanner(Syst         


        
8条回答
  •  天涯浪人
    2020-12-22 13:30

    1. Use Collections. Simple and easy.
    2. Use HashMap .
    3. parse the String you have read. For each character in the string, check if it is available in the map (as key). If yes, increment the count, else add the character to the map as key and set the count to 0.
    4. sort the map

提交回复
热议问题