在java中计算char

dat*_*ili 1 java algorithm

这段代码有什么问题?

import java.io.IOException;
import java.util.*;
public class char_digit {
    public static void main(String[] args) throws IOException {
        int count=0;

        while (true){
            char t=(char) System.in.read();
            if (t=='0'){
                break;
            }
            count++;

        }
        System.out.println(count);
    }
}


run:
a
b
c
d
e
f
0
12
Run Code Online (Sandbox Code Playgroud)

Ski*_*ick 8

你在计算换行符和其他字符.尝试类似if (t == '\n') continue;当前的事情if.