-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathvalidnumber.java
More file actions
25 lines (25 loc) · 841 Bytes
/
validnumber.java
File metadata and controls
25 lines (25 loc) · 841 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
public class valid_number {
public boolean isNumber(String S) {
boolean num = false, exp = false, sign = false, dec = false;
for (int i = 0; i < S.length(); i++) {
char c = S.charAt(i);
if (c >= '0' && c <= '9') num = true;
else if (c == 'e' || c == 'E')
if (exp || !num) return false;
else {
exp = true;
sign = false;
num = false;
dec = false;
}
else if (c == '+' || c == '-')
if (sign || num || dec) return false;
else sign = true;
else if (c == '.')
if (dec || exp) return false;
else dec = true;
else return false;
}
return num;
}
}