zoukankan      html  css  js  c++  java
  • Java正则匹配数字

    包括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

  • 相关阅读:
    例6-5
    例6-3
    例6-2
    例6-1
    例5-9
    python3
    python3
    python3
    python3
    python3
  • 原文地址:https://www.cnblogs.com/xuhuaiqu/p/4458552.html
Copyright © 2011-2022 走看看