String str=System.in.readline();
try{
int a=Integer.parseInt(str);
//继续}catch(NumberFormatException e){
System.out.println("不是整数!");
}
try{
int a=Integer.parseInt(str);
//继续}catch(NumberFormatException e){
System.out.println("不是整数!");
}
char c=str.charAt(i);
if(c>'9'||c<'0')
System.out.println("不是整数!");
}
//继续
for(int i=0;i<str.length;i++){
char c=str.charAt(i);
if(c>'9'||c<'0')
System.out.println("不是整数!");
}
public NumberFormatException()
Constructs a NumberFormatException with no detail message.
public static boolean isDigits(String str) {
if ((str == null) || (str.length() == 0)) {
return false;
}
for (int i = 0; i < str.length(); i++) {
if (!Character.isDigit(str.charAt(i))) {
return false;
}
}
return true;
}
上面代码引自jakarta-commons-lang-1.0.2: org.apache.commons.lang.NumberUtils