Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

public static double parseDouble(String s)

Posted on 2004-04-01
4
Medium Priority
?
1,205 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 24

Accepted Solution

by:
sciuriware earned 200 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

636 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