您的位置:首页 > 编程语言 > Java开发

java中如何判断输入的是英文还是中文

2009-07-27 14:15 489 查看
字符 人们使用的记号,抽象意义上的一个符号。 '1', '中', 'a', '$', '¥', ……
字节 计算机中存储数据的单元,一个8位的二进制数,是一个很具体的存储空间。 0x01, 0x45, 0xFA, ……

public class test {
public static void main(String[] args) {
String test = "aa";
byte []bytes = test.getBytes();
int i = bytes.length;//i为字节长度
int j = test.length();//j为字符长度
System.out.println(i+" "+j);
}
}
//output:2 2


public class test {
public static void main(String[] args) {
String test = "中国";
byte []bytes = test.getBytes();
int i = bytes.length;//i为字节长度
int j = test.length();//j为字符长度
System.out.println(i+" "+j);
}
}
//output:4 2


i是否等于j就可判断是纯中文或纯英语
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: