我已經從本網站上的一個很好的答案複製此代碼(計算字符串中的字符並返回計數),並已稍微修改它以適應我自己的需要。 但是,我似乎在我的方法中出現異常錯誤。計數字符方法異常錯誤?
我很感謝這裏的任何幫助。
請原諒我的代碼中的任何錯誤,因爲我仍在學習Java。
這裏是我的代碼:
public class CountTheChars {
public static void main(String[] args){
String s = "Brother drinks brandy.";
int countR = 0;
System.out.println(count(s, countR));
}
public static int count(String s, int countR){
char r = 0;
for(int i = 0; i<s.length(); i++){
if(s.charAt(i) == r){
countR++;
}
return countR;
}
}
}
這裏是個例外:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method count(String) in the type CountTheChars is not applicable for the arguments (int)
at CountTheChars.main(CountTheChars.java:12)
什麼是例外? – Makoto 2013-05-04 16:23:11
我已在上面添加。 – PrimalScientist 2013-05-04 16:24:12
我的猜測是你沒有重新編譯你的Eclipse項目。這樣做。 – Makoto 2013-05-04 16:26:30