查找输入字符串中出现字符次数最多的那个字和重复次数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了查找输入字符串中出现字符次数最多的那个字和重复次数相关的知识,希望对你有一定的参考价值。

public class chongfu {
//找出字符串中重复次数最多的那个字符;
/**
*

public static void main(String[] args){
System.out.println("请输入字符串");
Scanner a = new Scanner(System.in);
String b=a.nextLine();


int count=0;
int d=0;
char t = 0;

for(int i=0;i<b.length();i++){
count=0;
char c=b.charAt(i);
for(int j=0;j<b.length();j++){
if(c==b.charAt(j)){

count++;
if(d<count){
d=count;
t=b.charAt(j);
}
}

}

}
System.out.println("输入 的字符串中出现次数最多的字符是"+t+";总共出现"+d+"次");
}
* @param args
*/
}

 

 

这个可以找到正常的   担当出现两个或多个字符串的次数相同且都是出现次数最多的时,只出现第一个

以上是关于查找输入字符串中出现字符次数最多的那个字和重复次数的主要内容,如果未能解决你的问题,请参考以下文章