包括5种形式,如测试结果

import java.util.Scanner;
import java.util.regex.*;


public class Com {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String str=sc.nextLine();
            Pattern p = Pattern.compile("\\d+||\\d*\\.\\d+||\\d*\\.?\\d+?e[+-]\\d*\\.?\\d+?||e[+-]\\d*\\.?\\d+?");
            Matcher m = p.matcher(str);
            boolean b = m.matches();
            System.out.println(b);
        }
    }

}

 

 

34
true
2.34
true
.56
true
3e+45
true
3e-0.5
true
3e45
false

 posted on 2015-04-26 22:22  瀚海  阅读(11073)  评论(0编辑  收藏  举报