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

前端 未结 3 1188
北恋
北恋 2020-12-25 14:15
while( i <= j && i >= j && i != j) {}

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

// it\'s an interview q

3条回答
  •  暖寄归人
    2020-12-25 14:38

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

    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.

提交回复
热议问题