📄 countwriter.java
字号:
import java.io.*;public class CountWriter extends FilterWriter { private int count = 0; private char lookFor = 0; public CountWriter(Writer in, char lookFor) { super(in); this.lookFor = lookFor; } public void write(int character) throws IOException { super.write(character); if ((char)character == lookFor) { count++; } } public void write(char[] cbuf) throws IOException { super.write(cbuf); int length = cbuf.length; for (int i = 0; i < length; i++) { if (cbuf[i] == lookFor) { count++; } } } public void write(char[] cbuf, int off, int len) throws IOException { super.write(cbuf, off, len); int length = cbuf.length; for (int i = 0; i < length; i++) { if (cbuf[i] == lookFor) { count++; } } } public void write(String str) throws IOException { super.write(str); int length = str.length(); for (int i = 0; i < length; i++) { if (str.charAt(i) == lookFor) { count++; } } } public void write(String str, int off, int len) throws IOException { super.write(str, off, len); int length = str.length(); for (int i = 0; i < length; i++) { if (str.charAt(i) == lookFor) { count++; } } } public int getCount() { return count; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -