怎么能“a< = b&& b< = a&& a!= b“是真实的? [英] How can "a <= b && b <= a && a != b" be true?
问题描述
这是我必须弄清楚它是如何可能的代码。我有一个线索,但我不知道该怎么做。我认为它是负数和正数,也可能是变量修饰符。我是初学者,我到处寻找解决方案,但我找不到任何可用的东西。
Here is the code i have to figure it out how is it possible. I have a clue but i do not know how to do it. I think it is about negative and positive numbers and maybe the variable modifiers as well. I am a beginner i looked the solution everywhere but i could not find anything usable.
问题是:你需要声明并初始化这两个变量。 if条件必须为true。
the question is that: You need to declare and initialize the two variables. The if condition must be true.
代码:
if( a <= b && b <= a && a!=b){
System.out.println("anything...");
}
感谢您抽出宝贵时间。
I appreciate you taking the time.
推荐答案
原始类型无法做到这一点。你可以用盒装整数实现它:
This is not possible with primitive types. You can achieve it with boxed Integers:
Integer a = new Integer(1);
Integer b = new Integer(1);
< =
和> =
比较将使用未装箱的值1,而!=
将比较参考并将成功,因为它们是不同的对象。
The <=
and >=
comparisons will use the unboxed value 1, while the !=
will compare the references and will succeed since they are different objects.
这篇关于怎么能“a< = b&& b< = a&& a!= b“是真实的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!