📄 countspace.java
字号:
import java.io.*; //计算文件中的字符数和空白字符数
class CountSpace {
public static void main(String[] args) throws IOException {
InputStream in;
if (args.length == 0) {
in = System.in;
}
else {
in = new FileInputStream(args[0]);
}
int ch;
int total;
int spaces = 0;
for (total = 0; (ch = in.read()) != -1; total++) {
if (Character.isSpace( (char) ch)) {
spaces++;
}
System.out.println(total + "chars," + spaces + "spaces");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -