1、统计字符
String line = input.next();
count+=line.length(); /** 计算字符数 */
2、统计单词
按常规情况统计,未考虑其它情况
Pattern pattern = Pattern.compile("[a-zA-Z].*");
Matcher matcher = pattern.matcher(line); /** 英文单词数 */
if (matcher.find())
count1++;
3、示例
public class Test1 {
public static void main(String[] args) throws IOException {
File file = new File("protocol.txt");
Scanner input = new Scanner(file);
int count = 0, count1 = 0;
while (input.hasNext()) {
String line = input.next();
count+=line.length(); /** 计算字符数 */
Patt