
package com.logicbig.example.math;
public class SqrtExample {
public static void main(String... args) {
findSqrt(9.0);
findSqrt(25.0);
findSqrt(49.0);
findSqrt(65.0);
findSqrt(-81.0);
findSqrt(0.0);
findSqrt(0.0 / 0.0);
findSqrt(Double.POSITIVE_INFINITY);
}
private static void findSqrt(double a) {
double result = Math.sqrt(a);
System.out.printf("Math.sqrt(%s) = %s%n", a, result);
}
}
Output
Math.sqrt(9.0) = 3.0
Math.sqrt(25.0) = 5.0
Math.sqrt(49.0) = 7.0
Math.sqrt(65.0) = 8.06225774829855
Math.sqrt(-81.0) = NaN
Math.sqrt(0.0) = 0.0
Math.sqrt(NaN) = NaN
Math.sqrt(Infinity) = Infinity