Can (a==1 && a==2 && a==3) evaluate to true in Java?

后端 未结 8 745
梦如初夏
梦如初夏 2020-11-29 15:01

We know it can in JavaScript.

But is it possible to print \"Success\" message on the condition given below in Java?

if (a==1 && a==2 &&am         


        
8条回答
  •  我在风中等你
    2020-11-29 15:39

    Along similar lines, by forcing a float (or double) to underflow (or overflow) through division (or multiplication) by a large number:

    int a = 1;
    if (a / Float.POSITIVE_INFINITY == 1 / Float.POSITIVE_INFINITY
            && a / Float.POSITIVE_INFINITY == 2 / Float.POSITIVE_INFINITY
            && a / Float.POSITIVE_INFINITY == 3 / Float.POSITIVE_INFINITY) {
        System.out.println("Success");
    }
    

提交回复
热议问题