如何声明i和j使其成为无限循环? [英] how to declare i and j to make it be an infinite loop?

查看:176
本文介绍了如何声明i和j使其成为无限循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

while( i <= j && i >= j && i != j) {}

如何声明i和j使其成为无限循环?

how to declare i and j to make it be an infinite loop ?

//它是我遇到的面试问题。

// it's an interview question I met.

它询问i和j的声明是什么,使它始终为真。

it's asking what's the declarations of i and j, make it be always true.

我不能通过将i和j声明为数字类型来实现。还有哪些类型可以满足它?

And I cant make it out by declaring i and j as number types. What other types can meet it ?

推荐答案

Integer i=new Integer(1000);
Integer j=new Integer(1000);

System.out.println((i<=j)+" "+(i>=j)+" "+(i!=j));

i j 将自动取消装箱至< = > = 的整数,但不适用于!= i j 是不同的实例,但具有相同的int值。这就是为什么所有三个比较都将返回真实的原因。

i and j will be automatically unboxed to ints for <= and >=, but not for !=. i and j are different instances, but have the same int value. That's why all three comparisons will return true.

这篇关于如何声明i和j使其成为无限循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆