String numStr;
...
for (int i=0;i<numStr.length();i++){
try{
parseInt(numStr.charAt(i));
}
catch(NumberFormatException e){
System.out.println("the #"+i+"# is not a num!");
break;
}
}
...
for (int i=0;i<numStr.length();i++){
try{
parseInt(numStr.charAt(i));
}
catch(NumberFormatException e){
System.out.println("the #"+i+"# is not a num!");
break;
}
}
str = str.toLowerCase();
String strTemp = str;
char c = str.charAt(0);
if (!(c=='+' || c=='-' || Character.isDigit(c)))
return false;
else if (c=='+' || c=='-') strTemp = str.substring(1);
int size = strTemp.length();
for (int i=0; i<size; i++){
char tempChar = strTemp.charAt(i);
if (!(Character.isDigit(tempChar)||tempChar=='.'||tempChar =='e')) return false;
else {
if(tempChar=='.') {
if (i==0 || i==size-1) return false;
}
if(tempChar=='e'){
tempChar = str.charAt(i+1);
if (!(tempChar=='+' || tempChar=='-' || Character.isDigit(tempChar))) return false;
else {
if (tempChar=='+' || tempChar=='-'){
strTemp = str.substring(i+2);
}else {
strTemp = str.substring(i+1);
}
}
for (int ii=0; ii<strTemp.length(); ii++){
tempChar = strTemp.charAt(ii);
if (!Character.isDigit(tempChar)) return false;
}
return true;
}
}
}
return true;
}
...
for (int i=0;i<numStr.length();i++){
try{
new Integer(numStr.substring(i,i));
}
catch(NumberFormatException e){
System.out.println("the #"+i+"# is not a num!");
break;
}
}
String numStr;
...
for (int i=0;i<numStr.length();i++){
if(numStr.charAt(i)>47&&numStr.charAt(i)<58){
}else{
System.out.println("这不是一个数字!");
break;
}
}}