判断字符串是不是数字

Posted on 2016-06-10 22:13  上善其若水,厚德载物  阅读(169)  评论(0编辑  收藏  举报

NumberUtils.isNumber(str)判断字符串是不是数字或者能不能转换成数字

public class StringIsNumber {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String str = s.nextLine();
        if(NumberUtils.isNumber(str)){
            System.out.println("输入的是数字");
        }else{
            System.out.println("输入的不是数字");
        }        
        
    }
}

 NumberUtils是org.apache.commons.lang.math.NumberUtils所以看需不需要加个包

Copyright © 2024 上善其若水,厚德载物
Powered by .NET 8.0 on Kubernetes