Solved

public static double parseDouble(String s)

Posted on 2004-04-01
4
1,176 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

786 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