Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible for a==a to evaluate false for some variable a in Java?

Tags:

java

I've been posed this slightly obscure but interesting question about the behavoir of Java. Any ideas?

like image 237
CalumJEadie Avatar asked Apr 16 '26 05:04

CalumJEadie


1 Answers

Yep, Try this...

public class Main
{
  public static void main(String[] args)
  {
    double a = Double.NaN;
    if( a == a ) System.out.println("equal");
  }
}

http://www.ideone.com/K0d2j

like image 159
st0le Avatar answered Apr 18 '26 17:04

st0le