基于寻找字符串中次数最多的字母的优化
考虑的不是太全面,欢迎评论留言给出建议。
查找思路请点击下面的博客连接
https://blog.youkuaiyun.com/quaint_csdn/article/details/84102258
/*
* 程序入口
*/
public static void main(String[] args){
String str = "quaint,hello www WWWord!";
System.out.println("原字符串为:"+str);
System.out.println(getMaxCharAndNum(str));
}
/*
* 寻找一个字符串中出现次数最多的 字母
* 原理: 通过字符串分割函数分割字符串,判断分割后的长度来比较字母的次数.
*/
public static String getMaxCharAndNum(String str){
//存储最多出现的次数
int maxNum = 0;
//存储出现最多的字母
StringBuilder maxChar = new StringBuilder();