Topic: 新手求助!(如何用if判断用户输入值是否为整形)

  Print this page

1.新手求助!(如何用if判断用户输入值是否为整形) Copy to clipboard
Posted by: chentaolx
Posted on: 2006-12-08 07:46

请问我用JDBC编写数据库写入程序时~~若数据库的一个类型为整形,如何用if判断用户输入值是否为整形?? 求助各位高手`谢谢.

2.Re:新手求助!!! [Re: chentaolx] Copy to clipboard
Posted by: lisliefor
Posted on: 2006-12-08 14:06

就是判断用户输入是否全是数字字符:
String.charAt(int)
String.indexOf(String)
这两个方法配合使用,自己写一个判断函数吧!

3.Re:新手求助!!! [Re: chentaolx] Copy to clipboard
Posted by: chentaolx
Posted on: 2006-12-08 18:13

.....这个..谢谢帮助...但本人比较愚钝,能否给一个简单的例子?

4.Re:新手求助!!! [Re: chentaolx] Copy to clipboard
Posted by: lisliefor
Posted on: 2006-12-09 08:50

public boolean isNumber(String str,String num) {
boolean b = true;
for(int i=0;i<str.length();i++) {
if(num.indexOf(str.charAtLight Bulb) == -1)
b = false;
}
return b;
}

str为你需要判断的字符串,如果你是想判断str全为数字字符,那么传入的num为“0123456789”。当str不全为数字时,函数返回false,否则为true。

5.Re:新手求助!(如何用if判断用户输入值是否为整形) [Re: chentaolx] Copy to clipboard
Posted by: liushuiboy
Posted on: 2007-01-24 12:59

使用正则表达式

6.Re:新手求助!(如何用if判断用户输入值是否为整形) [Re: chentaolx] Copy to clipboard
Posted by: superfailure
Posted on: 2007-01-24 17:28

最简单的方法
try {
Integer.parseInt(str);
} catch(Exception e){
System.out.println("请输入整型");
}


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923