• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1211
  • Last Modified:

public static double parseDouble(String s)

For the following method, what does this return when empty string passed?

public static double parseDouble(String s)
                       
0
dkim18
Asked:
dkim18
  • 2
  • 2
1 Solution
 
sciuriwareCommented:
It won't return, but throw a NumberFormatException.
;JOOP!
0
 
sciuriwareCommented:
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
 
Mayank SAssociate Director - Product EngineeringCommented:
Just put the parseDouble () call in a try block and put a catch block for the NumberFormatException.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
try
{
  double d = Double.parseDouble ( "anything" ) ;

}

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now