第1个回答 推荐于2017-12-16
不用那么复杂,汉字俩字节,英文一个字节,计算下关系就可以了
public class Test {
public static void main(String[] args) {
Scanner s = new Scanner(System.in, "GBK");
String input = s.nextLine();
byte[] inputBytes = input.getBytes();
System.out.println("英文字符数:" + (2* input.length() - inputBytes.length));
System.out.println("汉字字符数:" + (inputBytes.length - input.length()) );
}
}本回答被提问者采纳