我正在做一些密碼分析作業,並試圖編寫代碼,做a + b = c。我的想法是使用unicode。 b +(b-a)= c。問題是我的代碼返回c的unicode值而不是String「c」,我無法將其轉換。將字符串「 u0063」的字符串轉換爲「c」
請有人可以解釋一下名爲unicode的字符串與那些名爲test和test2的區別嗎?還有什麼辦法可以讓字符串unicodeOfC打印「C」?
//this calculates the unicode value for c
String unicodeOfC = ("\\u" + Integer.toHexString('b'+('b'-'a') | 0x10000).substring(1));
//this prints \u0063
System.out.println(unicodeOfC);
String test = "\u0063";
//this prints c
System.out.println(test);
//this is false
System.out.println(test.equals(unicodeOfC));
String test2 = "\u0063";
//this is true
System.out.println(test.equals(test2));
非常好,我理解你的答案,並感謝額外的代碼,它的工作原理是如何工作的。非常感謝您的幫助。 – math125 2014-10-17 01:47:34