判断字符串是不是数字

Posted on 2016-06-10 22:13  上善其若水,厚德载物  阅读(174)  评论(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所以看需不需要加个包

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3