← all problems

countCapitals 🌶️

Write a method countCapitals that takes a String s and returns how many of its characters are capital letters (A to Z). Digits, spaces, punctuation and lowercase letters do not count.

For example, countCapitals("Hello World") is 2, and countCapitals("abc") is 0.