Solved

public static double parseDouble(String s)

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jboss wildfly 10.1 10 607
maven module vs maven project 3 113
Java ArrayList and if statement 2 55
junit initializtion error 2 20
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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 the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

732 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