Created
December 13, 2018 19:54
-
-
Save Eyad-Bereh/7ba2fb2a38a1eaae0f8b15e3fdc8d5f7 to your computer and use it in GitHub Desktop.
A java function to check whether an object is numeric
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//'main' method must be in a class 'Rextester'. | |
//Compiler version 1.8.0_111 | |
import java.util.*; | |
import java.lang.*; | |
class Rextester | |
{ | |
public static boolean isNumeric(Object parameter) { | |
try { | |
Long.parseLong(parameter.toString()); | |
} | |
catch (Exception e1) { | |
try { | |
Double.parseDouble(parameter.toString()); | |
} | |
catch(Exception e2) { | |
return false; | |
} | |
} | |
return true; | |
} | |
public static void main(String args[]) | |
{ | |
System.out.println(isNumeric("0.7777777777779999999999999")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment