【发布时间】:2017-03-24 00:08:34
【问题描述】:
在这种方法中,我计算数据文件中的字符类型。它成功计算了字符 A-Z(大写)、a-z(小写)和任何数字的数量,如果除了已经计算的字符之外还有任何其他类型的字符,我还需要它来计算。我尝试过的所有内容都计算了所有字符,没有字符,或者只有少数几个。
谢谢
public void countChars (){
String currentWord;
for(int pass = 0; pass < numberOfTokens; pass++){
currentWord = words[pass];
for (int i = 0; i < currentWord.length(); i++){
char ch = currentWord.charAt(i);
if (ch >= 'A' && ch <= 'Z'){
numberOfUpperCase++;
}
if (ch >= 'a' && ch <= 'z'){
numberOfLowerCase++;
}
if (ch >= '0' && ch <= '9'){
numberOfDigits++;
}
}
}
}//end of countChars
【问题讨论】:
-
为什么不用正则表达式?
-
什么意思?
标签: arrays if-statement char