Solved

public static double parseDouble(String s)

Posted on 2004-04-01
4
1,174 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:mayankeagle
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:mayankeagle
ID: 10739104
try
{
  double d = Double.parseDouble ( "anything" ) ;

}

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Basics of Drool Rule Engine with few samples 2 41
Fibonacci challenge 11 82
strCopies  challenge 17 73
Image decoding from Camera 3 44
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

707 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

21 Experts available now in Live!

Get 1:1 Help Now