Header javaperspective.com
JavaPerspective.com  >   Beginner Tutorials  >   5. Java in Practice  >   5.8. Java code exercises  >   5.8.5. Code exercise 5

5.8.5. Code exercise 5
Last updated: 27 January 2013.

Write a method named isDouble(String str) that returns true if the string argument can be parsed into a double value and false otherwise. If the string argument is null, the method returns false.


public final class Practice {

   
public boolean isDouble(String str){
         
if(str == null)
               
return false;

         
try{
               
Double.parseDouble(str);
               
return true;
         
}
         
catch(NumberFormatException e){
               
return false;
         
}
    }

}


You are here :  JavaPerspective.com  >   Beginner Tutorials  >   5. Java in Practice  >   5.8. Java code exercises  >   5.8.5. Code exercise 5
Next tutorial :  JavaPerspective.com  >   Beginner Tutorials  >   5. Java in Practice  >   5.8. Java code exercises  >   5.8.6. Code exercise 6

Copyright © 2013. JavaPerspective.com. All rights reserved.  ( Terms | Contact | About ) 
Java is a trademark of Oracle Corporation
Image 1 Image 2 Image 3 Image 4 Image 5 Image 6 Image 7