Home » Java programming language

Java Double class isInfinite() method with example

Double class isInfinite() method: Here, we are going to learn about the isInfinite() method of Double class with its syntax and example.
Submitted by Preeti Jain, on September 24, 2019

Double class isInfinite() method

  • isInfinite() method is available in java.lang package.
  • isInfinite() method is used to check infinity (i.e. either positive infinity or negative infinity).
  • isInfinite() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • isInfinite() method does not throw an exception at the time of checking infinity.

Syntax:

    public boolean isInfinite();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is boolean, it returns "true" if this object is either positive or negative infinity, else it returns "false".

Example:

// Java program to demonstrate the example 
// of isInfinite() method of Double class

public class IsInfiniteOfDoubleClass {
    public static void main(String[] args) {
        // Object initialization
        Double ob1 = new Double(10.0 / 0.0);
        Double ob2 = new Double(-20.0 / 0.0);
        Double ob3 = new Double(20.0);

        // Display ob1,ob2 and ob3 values
        System.out.println("ob1: " + ob1);
        System.out.println("ob2: " + ob2);
        System.out.println("ob3: " + ob3);

        // It checks infinity by calling ob1.isInfinite() for ob1
        // and ob2.isInfinite() for ob2 and ob2.isInfinite() for ob3 
        boolean infinite1 = ob1.isInfinite();
        boolean infinite2 = ob2.isInfinite();
        boolean infinite3 = ob3.isInfinite();

        // Display result values
        System.out.println("ob1.isInfinite(): " + infinite1);
        System.out.println("ob2.isInfinite(): " + infinite2);
        System.out.println("ob3.isInfinite(): " + infinite3);
    }
}

Output

ob1: Infinity
ob2: -Infinity
ob3: 20.0
ob1.isInfinite(): true
ob2.isInfinite(): true
ob3.isInfinite(): false






Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.