解题思路:

Character.isDigit()方法和String.matches()

public static void main(String[] args) {
        String str = "123458766";
      //  System.out.println(str.matches("[0-9]+"));
        System.out.println(checkIsDigit("868763"));
    }

    public static boolean checkIsDigit(String str){
        char[] chars = str.toCharArray();
        for(int i = 0 ;i < chars.length; i++){
            if(!Character.isDigit(chars[i])){
                return false;
            }
        }
        return true;
    }

 

posted on 2022-01-27 13:46  安安安happy  阅读(179)  评论(0编辑  收藏  举报