java中的符号计数方法
我正在使用一个程序读取一个文本文件,然后计算数字(大写、小写、空格)。我的问题是,如何将文本的其余部分(数字,“.()/:;)一起计算
下面是一些代码
for (int b = 0; b < crunchifyLine.length(); b++) {
if (Character.isUpperCase(crunchifyLine.charAt(b))) {
UppeLetter++;
}
}
for (int b = 0; b < crunchifyLine.length(); b++) {
if (Character.isLowerCase(crunchifyLine.charAt(b))) {
LowerLetter++;
}
}
for (int c = 0; c < crunchifyLine.length(); c++) {
if (Character.isWhitespace(crunchifyLine.charAt(c))) {
spaceNum++;
}
}
# 1 楼答案
这不是一个优雅的解决方案,但它仍然适用于您:
# 2 楼答案
基于“部分代码”,我将其更改为更类似于:
另一种方法是:
同样对于样式,您混合了以小写字母开头的变量和以大写字母开头的变量,您可以看到the automatic syntax highlighter标记通常意味着不同的东西(尽管这只是惯例)