b*******h 发帖数: 53 | 1 求各位大牛指导, 这个题目我扫描整个string。用boolean表示当前的状态, 每个
char可以看之前的状态进行判断,逻辑上是不是比较清楚一点。贴上代码:
public boolean isNumber(String s) {
s = s.trim();
if(s.length() == 0) return false;
if(s.charAt(0) == '+' || s.charAt(0)=='-') return isNum(s.substring(
1,s.length()));
else return isNum(s);
}
public boolean isNum(String s){
boolean hasInteger = false, hasDot = false, hasDecimal = false,
hasPow = false, hasSign = false, hasExponent = false;
for (ch... 阅读全帖 |
|
b*******h 发帖数: 53 | 2 求各位大牛指导, 这个题目我扫描整个string。用boolean表示当前的状态, 每个
char可以看之前的状态进行判断,逻辑上是不是比较清楚一点。贴上代码:
public boolean isNumber(String s) {
s = s.trim();
if(s.length() == 0) return false;
if(s.charAt(0) == '+' || s.charAt(0)=='-') return isNum(s.substring(
1,s.length()));
else return isNum(s);
}
public boolean isNum(String s){
boolean hasInteger = false, hasDot = false, hasDecimal = false,
hasPow = false, hasSign = false, hasExponent = false;
for (ch... 阅读全帖 |
|