/**
* @param args
*/
public static void main(String[] args) {
TestMain t = new TestMain();
boolean flag = t.CheckNumbers("0.8*(1/e pow ((x-200)/100))+0.2");
//boolean flag = t.CheckNumbers("0.8");
if(flag){
System.out.println("TRUE");
}else{
System.out.println("FALSE");
}
}
/**
* 验证字符串是否为整数或小数
* @param str
* @return
*/
public boolean CheckNumbers(String str)
{
//Pattern pattern = Pattern.compile("/^[\\+\\-]?\\d*?\\.?\\d*?$/"); //错误
Pattern pattern = Pattern.compile("\\d+(.\\d+)?$");
Matcher isNum = pattern.matcher(str);
if( !isNum.matches() )
{
return false;
}
return true;
}
|
|