【发布时间】:2014-10-17 01:20:14
【问题描述】:
我正在做一些密码分析作业,并试图编写执行 a + b = c 的代码。我的想法是使用 unicode。 b +(b-a) = c。问题是我的代码返回 c 的 unicode 值而不是字符串“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));
【问题讨论】: