jsp中,如何判断字符串(String)是数字(int)并转换为数字(int) rt 3x! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /** * 无异常的parseInt方法 * @param s * @return */ public static int parseInt(String s) { if (s == null) { return 0; } try { return Integer.parseInt(s); } catch (NumberFormatException nfe) { return 0; } } int ia=0;String str="123";try{ ia=Integer.parseInt(str);}catch{ ia=0; System.out.println(str+"不是数字");} 不好意思,上面那个没有写完整 int ia=0;String str="123";try{ ia=Integer.parseInt(str);}catch(NumberFormatException e){ ia=0; System.out.println(str+"不是数字");} 楼上的都可以,我也来写一种, public boolean IsNumber(String str) { String number_chars = "1234567890"; for (int i=0;i<str.length();i++) { if(number_chars.indexOf(str.charAt(i))==-1) return false; } return true; } c#突然接触java,好多问题不懂了,莫笑话。 SSH框架整合问题 如果一个logic:itetate 中有个属性也是集合类型,该属性也需要循环输出 jsp框架问题 奇怪的按钮不响应问题,毫无思路。 招聘:广东佛山市高明区金得利科技有限公司招聘JSP程序员,待遇从优。 BeanUtils.copyProperties问题 你们有没有想过这个问题???? jsp中去掉字符串中的空客? 关于FORM提交数据的问题,若能解决我给你200分! 如何做白盒测试? 请指点一下 为什么老是显示????号啊!
/**
* 无异常的parseInt方法
* @param s
* @return
*/
public static int parseInt(String s) {
if (s == null) {
return 0;
}
try {
return Integer.parseInt(s);
}
catch (NumberFormatException nfe) {
return 0;
}
}
String str="123";
try
{
ia=Integer.parseInt(str);
}catch{
ia=0;
System.out.println(str+"不是数字");
}
int ia=0;
String str="123";
try
{
ia=Integer.parseInt(str);
}catch(NumberFormatException e){
ia=0;
System.out.println(str+"不是数字");
}
public boolean IsNumber(String str)
{
String number_chars = "1234567890";
for (int i=0;i<str.length();i++)
{
if(number_chars.indexOf(str.charAt(i))==-1)
return false;
}
return true;
}