Solved

public static double parseDouble(String s)

Posted on 2004-04-01
4
1,175 Views
Last Modified: 2012-06-21
For the following method, what does this return when empty string passed?

public static double parseDouble(String s)
                       
0
Comment
Question by:dkim18
  • 2
  • 2
4 Comments
 
LVL 24

Accepted Solution

by:
sciuriware earned 50 total points
ID: 10739021
It won't return, but throw a NumberFormatException.
;JOOP!
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 10739029
You can easily test this:


public class Program
{
   public static void main(String[] argv)
   {
      double answer = Double.parseDouble("");
      System.out.println("It produced:" + answer);
   }
}
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10739098
Just put the parseDouble () call in a try block and put a catch block for the NumberFormatException.
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 10739104
try
{
  double d = Double.parseDouble ( "anything" ) ;

}

catch ( NumberFormatException e )
{
  // if it enters here - the format was incorrect
}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
java. non-English characters encoding problem. intellij idea 3 74
github account with ecipse 1 42
Java JRE greater than 1.6 5 50
Java DateChooser? 3 29
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now