- Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy pathValidNumber65.java
More file actions
Latest commit
26 lines (25 loc) · 643 Bytes
/
Copy pathValidNumber65.java
File metadata and controls
26 lines (25 loc) · 643 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/**
* 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.
*/
publicclassValidNumber65 {
publicbooleanisNumber(Strings) {
try {
Double.valueOf(s);
} catch (Exceptione1) {
returnfalse;
}
charlast = s.charAt(s.length()-1);
if(last == 'D' || last == 'd' || last == 'f' || last == 'F') returnfalse;
returntrue;
}
}