Link to home
Start Free TrialLog in
Avatar of dkim18
dkim18

asked on

public static double parseDouble(String s)

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

public static double parseDouble(String s)
                       
ASKER CERTIFIED SOLUTION
Avatar of sciuriware
sciuriware

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sciuriware
sciuriware

You can easily test this:


public class Program
{
   public static void main(String[] argv)
   {
      double answer = Double.parseDouble("");
      System.out.println("It produced:" + answer);
   }
}
Avatar of Mayank S
Just put the parseDouble () call in a try block and put a catch block for the NumberFormatException.
try
{
  double d = Double.parseDouble ( "anything" ) ;

}

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