当前位置: 技术问答>java相关
请问如何才能判断text中输入的是否为数值类型呢?
来源: 互联网 发布时间:2015-02-09
本文导语: 不用javascript的isNaN()判断成么?用jsp判断怎么实现? | /*判断整形数据,先编译,在测试。 javac TestNum.java 编译通过 java TestNum [你要测试的串] 如:java TestNum 8o00 则提示:Your string IS NOT NUM...
不用javascript的isNaN()判断成么?用jsp判断怎么实现?
|
/*判断整形数据,先编译,在测试。
javac TestNum.java
编译通过
java TestNum [你要测试的串]
如:java TestNum 8o00
则提示:Your string IS NOT NUMBER!
*/
public final class TestNum
{
public static boolean convertInt(String str)
{
try
{
int n = Integer.parseInt(str);
return true;
}
catch(NumberFormatException e)
{
//e.printStackTrace();
return false;
}
}
public static void main(String[] args)
{
if (args.length != 1)
{
System.out.println("Please input a STRING that you would test!");
}
else
{
String aa=args[0];
boolean bln = convertInt(aa);
if (bln==true)
{
System.out.println("Your string IS NUMBER!");
}
else
{
System.out.println("Your string IS NOT NUMBER!");
}
}
}
}
javac TestNum.java
编译通过
java TestNum [你要测试的串]
如:java TestNum 8o00
则提示:Your string IS NOT NUMBER!
*/
public final class TestNum
{
public static boolean convertInt(String str)
{
try
{
int n = Integer.parseInt(str);
return true;
}
catch(NumberFormatException e)
{
//e.printStackTrace();
return false;
}
}
public static void main(String[] args)
{
if (args.length != 1)
{
System.out.println("Please input a STRING that you would test!");
}
else
{
String aa=args[0];
boolean bln = convertInt(aa);
if (bln==true)
{
System.out.println("Your string IS NUMBER!");
}
else
{
System.out.println("Your string IS NOT NUMBER!");
}
}
}
}
|
试试:
boolean result=false;
for (int i = 0; i
boolean result=false;
for (int i = 0; i