我执行以下代码并且没有错误,在输出中我看到Success!
消息。你能解释一下这种奇怪的行为吗?
public class Main {
public static void main(String[] args) {
int р = 0;
int p = 1;
if(р == 0 && p == 1) {
System.out.println("Success!");
}
}
答案 0 :(得分:11)
两者都是不同的变量(但看起来相似),你可以看到UTF-16不同
int р = 0;
int p = 1;
if (р == 0 && p == 1) {
System.out.println("Success!");
System.out.println("p UTF-16 is " + (int) 'p');
System.out.println("р UTF-16 is " + (int) 'р');
}
输出
Success!
p UTF-16 is 112
р UTF-16 is 1088