Online Java Compiler By
JavaTpoint.com
import java.util.Scanner; public class Double_isNaNMethodExample3 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter two double no.\n1. Enter Positive double number = "); Double d1 = scanner.nextDouble(); double d2 = (float) Math.sqrt(d1); System.out.println("Ans. Square root of " + d1 + " value = " + d2); System.out.println("2. Enter Negative double number ="); Double d3 = scanner.nextDouble(); double d4 = (double) Math.sqrt(d3); // cube root of negative isNan if (Double.isNaN(d4)) { System.out.println("Ans. Square root of " + d3 + " value = " + d4); } else{ System.out.println("Plz enter a negative integer."); } } }
Output