Scanner input=new Scanner(System.in);
System.out.println("输入你要转换的字符串:");
String str=input.next();
String result="";
for (int i = 0; i < str.length(); i++){
char ch = str.charAt(i);
if(ch>=19968&&ch<=171941){
//判断是否为中文(汉字范围 \u4e00-\u9fa5 (中文))
result+=ch+":"+"\\u" + Integer.toHexString(ch)+"\n";
}else{
result+=str.charAt(i);
}
}
System.out.println(result);
你的Unicode对应的编码好像是不对的,是乱写的?
本回答被网友采纳