`
modabobo
  • 浏览: 509556 次
文章分类
社区版块
存档分类
最新评论

查找一个字符串中最长的字符及个数

 
阅读更多
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);
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics