java.lang.Float isInfinite() and isInfinite(float f)
Description
- isInfinite() – Returns true if this Float value is infinitely large in magnitude, false otherwise.
- isInfinite(float f) – Returns true if the argument is a finite floating-point value; returns false otherwise (for NaN and infinity arguments).
Method Syntax
The following are the two isInfinite method of Float class
1.
public boolean isInfinite()
2.
public static boolean isFinite(float f)
Compatibility
Java 1.0
Java Float isInfinite() Example
Below is a simple java example on the usage of isInfinite() method of Float class.
package com.javatutorialhq.java.examples; import java.util.Scanner; import static java.lang.System.*; /* * This example source code demonstrates the use of * isInfinite() method of Float class. */ public class FloatIsInfiniteExample { public static void main(String[] args) { // Ask user input System.out.print("Enter Desired Value:"); // declare the scanner object Scanner scan = new Scanner(System.in); // use scanner to get value from user console Float userInput = scan.nextFloat(); // close the scanner object scan.close(); // check if the float input is inFinite boolean check = userInput.isInfinite(); out.println("is the value entered infinite? " + check); } }
Basically on the above example, we just ask for user input on the console and then we use the scanner object to get the float input. After that we assign the value to an Float wrapper class and we then we check if the user input is an infinite floating point number.