题目:表示数值的字符串
不喜欢这道题目,偷懒用Java正则表达式和String类的方法来处理了
public static boolean isNumeric(String str){
String regex="[+-]?\\d*(\\.\\d*)?([eE][+-]?\\d+)?";
return str.matches(regex);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
String [] strArr={"+100","5e2","-123","-1E-16",".365","12e","+-5"};
for(String str:strArr){
System.out.println(Problem20.isNumeric(str));
}
}
true
true
true
true
true
false
false