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的值的