Describe
Validate if a given string is numeric.
Some Examples:
"0" = True
"0.1" = True
"ABC" = False
"1 A" = False
"2e10" = True
Note:it is intended for the problem statement to be ambiguous. You should gather all requirements
Up front before implementing one.
Analysis
Detail implementation questions.
The function of the subject is similar to the strtod () function in the standard library
Valid numbers, with regular
Code
1 Public classVaildnumber {2 3 Public Static voidMain (string[] args) {4 //TODO auto-generated Method Stub5 //String s= "2e10";6String s= "1.5e10";7 System.out.println (Vaildnumber (s));8 }9 Private Static BooleanVaildnumber (String s) {Ten if(S.length () ==0)return false; One //"0" = True A //"0.1" = True - //"abc" = False - //"1 A" = False the //"2e10" = True -String regex= "\\d+ (\\.\\d+)? (e\\d+)? " ; - returns.matches (regex); - } +}
Valid number Leetcode Java