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;
}
}
}
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
Next tutorial : JavaPerspective.com > Beginner Tutorials > 5. Java in Practice > 5.8. Java code exercises > 5.8.6. Code exercise 6