How to make loop infinite with “x <= y && x >= y && x != y”?

前端 未结 4 818
南方客
南方客 2020-12-16 11:07

I had this interview question some years ago but I haven\'t found the answer yet.

What should be x and y to make a infinite loop?

while (x <= y&am         


        
4条回答
  •  借酒劲吻你
    2020-12-16 11:47

    You've got your answer, I just wanted to say how I got to the same one. In the normal world such a test would be useless, there is no way for two number to work like that. So that means it HAS to be some java specific.

    x and y could be either simple types - which makes it impossible right away.

    x and y could be objects. But what objects are compared with <= or >=? Only 'boxed' numbers. Thus the answer comes up really fast.

提交回复
热议问题