← Unit 4 · all exercises
Saved in this browser only

Count a character

Return how many times the given single character appears in the text. Capitals count as different characters.

int countOf(String text, String letter)

Solution.java
Loading editor…
Results

Examples

  • Solution.countOf("banana", "a") → 3
  • Solution.countOf("banana", "z") → 0

There are also 3 hidden tests you can't see. Solve the problem, not the examples.