public static void main(String[] args) {
test("abbcccddddaa");
}
public static void test(String str) {
int max_length = 0;
String max_str = "";
while (str.length() > 0) {
int length = str.length();
String first = str.substring(0, 1);
str = str.replaceAll(first, "");
if (max_length < length - str.length()) {
max_length = length - str.length();
max_str = first;
}
}
System.out.println(max_length);
System.out.println(max_str);
}
本文提供了一个简单的Java程序示例,该程序用于找出一个字符串中出现次数最多的字符及其出现次数。通过对输入字符串进行处理,程序首先统计每个字符的出现频率,然后输出出现次数最多的字符及其次数。
2521

被折叠的 条评论
为什么被折叠?



