当前位置: 技术问答>java相关
怎么判断输入的是数字?谢谢
来源: 互联网 发布时间:2015-01-24
本文导语: | String mystr=request.getParameter("num"); String thestr="0123456789"; if(thestr.indexOf(mystr)==-1) { out.println("your input isn't a number"); } else { out.println("your input is "+mystr+"!"); } | 可以用String的charAt(int index)来判断,...
|
String mystr=request.getParameter("num");
String thestr="0123456789";
if(thestr.indexOf(mystr)==-1)
{
out.println("your input isn't a number");
}
else
{
out.println("your input is "+mystr+"!");
}
String thestr="0123456789";
if(thestr.indexOf(mystr)==-1)
{
out.println("your input isn't a number");
}
else
{
out.println("your input is "+mystr+"!");
}
|
可以用String的charAt(int index)来判断,土了点,呵呵