注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
/*
* Returns true if the input string is a number and false otherwise
*/
//-10,10, 1.
//10, 1.0 , 0.1, -2
// .5
public boolean isNumber(String toTest)
{
// implementation here
String str = toTest.trim();
boolean hasNumberBefore = false;
boolean hasPointBefore = false;
for (int i = 0; i < str.length(); i++) {
char curr = str.charAt(i);
if (curr == '-' && i != 0) {
return false;
} else if (Character.isDigit(curr)) {
hasNumberBefore = true;
} else if (curr == '.') {
if (hasNumberBefore == false || hasPointBefore == true) {
return false;
}
UE;
while (index1 < indexOne.size() && index2 < indexTwo.size()) {
int curr1 = indexOne.get(index1), curr2 = indexTwo.get(index2);
if (curr1 < curr2) {
min = Maht.min(min, curr2 - curr1);
index1++;
} else {
min = Maht.min(min, curr1 - curr2);
index2++;
}
}
return min;
}
}
|