I have copied this code from a good answer on this website (counting characters in a String and returning the count) and have slightly amended it to suit my own needs. However, I seem to be getting an exception error in my method.
I would appreciate any help here.
Please forgive any errors in my code as I am still learning Java.
Here is my code:
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;
}
}
}
Here is the exception:
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)