Answer:
Check the explanation
Step-by-step explanation:
public static int countMatching(String s, char c) {
int count = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == c)
++count;
}
return count;
}
Method in a complete Java program
public class FizzBuzz {
/* sample run:
* z appears 2 time(s) in FIZZbuzz
*/
public static void main(String[] args) {
String s = "FIZZbuzz";
char c = 'z';
int count = countMatching(s, c);
System.out.printf("%c appears %d time(s) in %s%n", c, count, s);
}
// Put your countMatching() method here:
public static int countMatching(String s, char c) {
int count = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == c)
++count;
}
return count;
}
}
z appears 2 time(s) in FIZZbuzz Process finished with exit code