0
public static void main (String[] args) {
char[] msg;
int code;
int i;
String newMsg;
msg = getMsg(); // Read the message from keyboard
code = getCode();
System.out.println("Code : "+code);
for (i=0; i<msg.length; i++){
System.out.println(msg[i]);
System.out.println(Character.toString((char)msg[i]));
newMsg = ("\\u" + Integer.toHexString(msg[i] + code | 0x10000).substring(1));
System.out.println (String.valueOf(msg[i] + code));
System.out.println (newMsg);
}
public static int getCode(){
int code=0;
System.out.print("Input Code: ");
Scanner input = new Scanner(System.in);
return input.nextInt();
}
public static char[] getMsg(){
String myMessage;
System.out.print("Input Message: ");
Scanner input = new Scanner(System.in);
myMessage = input.nextLine();// Read a line of message
return myMessage.toCharArray();
}
我的输出如下:打印Unicode +位数为Unicode
输入消息:一个 输入码:1个 码:1 一个 一个 \ u0062
我试图在这种情况1中添加CODE并打印b,但我只能将它添加到unicode或ascii,但我不能从那里回到b。型char
这里'a'
的值和int
类型这里1的值的