基本上,我必须编写一个方法来确定字符串中的所有字符是否相同,只使用库 String 方法。
问问题
101 次
3 回答
0
于 2013-02-13T07:00:20.403 回答
0
public static void main(String[] args) {
String str = "aaaaa";
int count = str.length() - str.replaceAll(String.valueOf(str.charAt(0)), "").length();
if(count == str.length())
System.out.println("All characters in a given String are same");
}
试试这个:这是解决这类问题的最简单和最好的解决方案。
于 2013-02-13T07:32:41.683 回答