Menu
Topics Index
...
`

isInfiniteandisNanDemo - Java Example Program


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.

© meritcampus 2019

All Rights Reserved.

Open In App