Java Double parseDouble() MethodThe parseDouble method of Java Double class returns a new double value that is initialized to the value corresponding to defined String. This method executes same as valueOf() method of Float class. SyntaxParameterss- This is the string to be parsed. Return valueThe parseDouble() method returns the double value corresponding to the parameter passed. ThrowsThe parseDouble() method throws: 1.NullPointerException- if the string passed is null. 2.NumberFormatException- if the string passed does not hold a parsable float. Example 1Output: 1. Sum =1000156.0 2. Sum =1156.0 3. Multiplication =156000.0 4. Division =6.410256410256411 5. Reminder =64.0 Example 2Output: Enter your age:09 Sorry! You are not eligible.Try again after 44.0 years Your year of birth is = 2009.0 Example 3Output: Enter any string:Himanshu@123 Exception in thread "main" java.lang.NumberFormatException: For input string: "Himanshu@123" at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043) at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110) at java.lang.Double.parseDouble(Double.java:538) Example 4Output: Enter any string:himanshu@123 An exception java.lang.NumberFormatException: For input string: "himanshu@123" has occured. Plz enter a valid double integer Next TopicJava-double-shortvalue-method |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India