Java Puzzle 22 – NaN

Merhaba Arkadaslar ,
Bu while dongusu number’in hangi durumu/degeri icin calisacaktir ?

while (number != number) {

}

Java’da Infinity degeri gibi NaN (Not a Number) degeri de mevcuttur.

0.0/0.0

NaN.java

package _22.nan.loop;

public class NaN {

	public static void main(String[] args) {
		double number = 0.0 / 0.0;

		System.out.println(number); // NaN

		System.out.println(number - number); // NaN

		System.out.println(number == number); // false
	}
}

NaNLoop.java

package _22.nan.loop;

public class NaNLoop {

	public static void main(String[] args) {
		double number = Double.NaN;
		while (number != number) {
			System.out.println("works or not?");
		}
	}
}

Github kaynak kodlar / Source Code ;
leventerguder/injavawetrust-puzzler

Yazimi burada sonlandiriyorum.
Herkese Bol Javali Gunler dilerim.
Be an oracle man , import java.*;
Levent Erguder
OCP, Java SE 6 Programmer
OCE, Java EE 6 Web Component Developer

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *