Test the Java code with boundary values
In this step, we will test the Java code with boundary values to see how isFinite()
method works.
Modify the main()
method as follows:
public static void main(String[] args) {
double d1 = Double.MIN_VALUE;
double d2 = Double.MAX_VALUE;
double d3 = Double.POSITIVE_INFINITY;
double d4 = Double.NaN;
printIsFinite(d1);
printIsFinite(d2);
printIsFinite(d3);
printIsFinite(d4);
}
The main method uses the MIN_VALUE
and MAX_VALUE
constants of the Double
class to assign the smallest and largest finite double values, respectively, to d1
and d2
, and assigns positive infinity and NaN values to d3
and d4
, respectively.
Recompile and run the Java code using the commands below:
javac DoubleIsFiniteDemo.java
java DoubleIsFiniteDemo
The output of the program should be:
4.9E-324 is a finite double value.
1.7976931348623157E308 is a finite double value.
Infinity is not a finite double value.
NaN is not a finite double value.