我必须解决一个练习,递归地计算字符串中的所有大写字符 - 无论如何,我想我可能找到了解决方案 - 但它不会工作... 也许你可能会帮助我?谢谢!递归计算字符串中的大写字母
public static int CountCapitals(String s) {
int counter = 0;
// if (Character.isUpperCase(s.charAt(0)))counter+=1;
if (s.length() == 0)
return counter;
if (s.length() == 1 && s.charAt(0) < 65 && s.charAt(0) > 90)
return 0;
if (s.charAt(0) < 'A' && s.charAt(0) > 'Z') {
return CountCapitals(s.substring(1));
}
if (s.charAt(0) >= 'A' && s.charAt(0) <= 'Z')
counter++;
return CountCapitals(s.substring(1));
}
欢迎来到Stackoverflow!你用你的代码遇到了什么问题?请详细解释您的具体问题。 –
你应该参加[tour](http://stackoverflow.com/about)。 –