Skip to content

Instantly share code, notes, and snippets.

@Eyad-Bereh
Created December 13, 2018 19:54
Show Gist options
  • Save Eyad-Bereh/7ba2fb2a38a1eaae0f8b15e3fdc8d5f7 to your computer and use it in GitHub Desktop.
Save Eyad-Bereh/7ba2fb2a38a1eaae0f8b15e3fdc8d5f7 to your computer and use it in GitHub Desktop.
A java function to check whether an object is numeric
//'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