Menu
Topics Index
...
`


Exploring java.lang > Primitive Type Wrappers >
Siva Nookala - 05 Apr 2016
Double wrapper class has two methods isInfinite and isNaN. isInfinite method checks whether a value is infinite and isNaN checks whether a value is NaN(Not a Number).

Method Description
isInfinite Returns true if the value is infinitely large or small in magnitude. Otherwise it is false
isNaN Returns true if the value is not a number. Otherwise false
isInfiniteandisNanDemo
class isInfiniteandisNanDemo
{
    public static void main(String arg[])
    {
        Double d1 = new Double(2.0 / 0.0);
        Double d2 = new Double(0 / 0.0);
        System.out.println(d1 + ": " + d1.isInfinite());
        System.out.println(d2 + ": " + d2.isNaN());    
    }
}
OUTPUT

Infinity: true
NaN: true

DESCRIPTION

At LINE A the output is true, Since the value is infinity. At LINE B the output is true, Since the value is NaN(Not a Number).

THINGS TO TRY
  • Change the value of d1 to any positive or negative number and check the output. The output will become false at LINE A.
  • Change the value of d2 to any positive or negative number and check the output. The output will become false at LINE B.

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App