java中判断字符串是否为数字的三种方法
来源:互联网 发布:怎样成为一名网络作家 编辑:程序博客网 时间:2024/06/05 09:35
文章出处:http://www.blogjava.net/Javaphua/archive/2007/06/05/122131.html
1用JAVA自带的函数
public static boolean isNumeric(String str){for (int i = str.length();--i>=0;){
if (!Character.isDigit(str.charAt(i))){
return false;
}
}
return true;
}
2用正则表达式
public static boolean isNumeric(String str){
Pattern pattern = Pattern.compile("[0-9]*");
return pattern.matcher(str).matches();
}
3用ascii码
public static boolean isNumeric(String str){
for(int i=str.length();--i>=0;){
int chr=str.charAt(i);
if(chr<48 || chr>57)
return false;
}
return true;
}
- java中判断是否为数字的三种方法
- java中判断字符串是否为数字的三种方法
- java中判断字符串是否为数字的三种方法
- java中判断字符串是否为数字的三种方法
- java中判断字符串是否为数字的三种方法
- java中判断字符串是否为数字的三种方法
- java中判断字符串是否为数字的三种方法
- java中判断字符串是否为数字的三种方法
- java中判断字符串是否为数字的三种方法
- java中判断字符串是否为数字的三种方法
- java中判断字符串是否为数字的三种方法
- java中判断字符串是否为数字的三种方法
- java中判断字符串是否为数字的三种方法
- java中判断字符串是否为数字的三种方法
- java中判断字符串是否为数字的三种方法
- java中判断字符串是否为数字的三种方法
- Java中判断字符串是否为数字的三种方法
- java中判断字符串是否为数字的三种方法
- 编写java程序求裴波那契数列前20项和
- hdu 1788 Chinese remainder theorem again
- CSUST 1530 快速找钱
- could not exec dpkg!解决
- 生成树计数-Matrix-Tree定理
- java中判断字符串是否为数字的三种方法
- 【Python基础】之对字典进行排序操作(sort by the values of dict)
- uva_11795_Mega Man's Mission( 簡單狀壓DP )
- 【练习02】 简单题(2)1001 Higher Math
- 关于inline函数
- taintdroid4.1下载编译
- "Wireless Network Connection" doesn't have a valid IP configuration - Not fixed
- 第九周项目一
- overlay实现帧动画