求具体代码:怎么判断一个字符串是个数字,如果是数字,是int/long/float那一种? 用Double.parseDouble(string),如果捕到异常,则说明不是数字。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 具体类型的判断我只在jxl.jar包里面的方法c00.getType()实现过,具体还有没有其他的方法来实现,具体去查询一下!关注! 你可以考虑使用正则表达式来判断是否是数字.如果是数字,呃,我问你2是一个什么类型,int or long or other types? 不要用异常来判断,影响效率,而且用异常控制流程是个非常差的习惯 public static boolean isNumber(String s) { boolean pointfirsttime = true; int i = 0; if (s == null) { return false; } if (s.charAt(0) == '-') { i++; } while (i < s.length()) { if (!Character.isDigit(s.charAt(i))) { if ('.' == s.charAt(i) && pointfirsttime) { pointfirsttime = false; } else { return false; } } i++; } return true; }至于是什么类型,不好说吧 try:String data = "这里放你要想匹配的字符串";String pattern = "^\\s*(\\+|-)?\\d+(\\.\\d+)?\\s*$";Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(data); if(m.matches()) System.out.println("match"); else System.out.println("not match"); 如何让JDialog置顶(JDK1.4)? Java写个时间转换程序 一个垃圾回收的问题 将来要做Java工程师?我现在应该有哪些知识? 请教了(来者有分) 有关java断言的一个问题? 剩2个bug就可以运行了,帮忙! 为什么不能这样强制转换? UCS2编码问题~ 急急急!!! UP有分!UP有分!--关于构造函数之间的相互调用,提一个大家都会遇到的问题!--UP有分!UP有分! 连接sql server 2000出错,麻烦大家帮忙!
c00.getType()实现过,具体还有没有其他的方法来实现,具体去查询一下!关注!
{
boolean pointfirsttime = true; int i = 0;
if (s == null) {
return false;
}
if (s.charAt(0) == '-') {
i++;
}
while (i < s.length()) {
if (!Character.isDigit(s.charAt(i))) {
if ('.' == s.charAt(i) && pointfirsttime) {
pointfirsttime = false;
} else {
return false;
}
}
i++;
}
return true;
}至于是什么类型,不好说吧
String pattern = "^\\s*(\\+|-)?\\d+(\\.\\d+)?\\s*$";
Pattern p = Pattern.compile(pattern);
Matcher m = p.matcher(data);
if(m.matches())
System.out.println("match");
else
System.out.println("not match");