发布网友 发布时间:2022-04-22 03:08
共1个回答
热心网友 时间:2023-06-23 11:41
方法一:利用正则表达式publicclassTestone{publicstaticvoidmain(String[]args){Stringstr="123456";booleanresult=str.matches("[0-9]+");if(result==true){System.out.println("该字符串是纯数字");}else{System.out.println("该字符串不是纯数字");}}}方法二:利用Pattern.importjava.util.regex.Matcher;importjava.util.regex.Pattern;publicclassTestone{publicstaticvoidmain(String[]args){Stringstr="123456";Patternpattern=Pattern.compile("[0-9]{1,}");Matchermatcher=pattern.matcher((CharSequence)str);booleanresult=matcher.matches();System.out.println("该字符串是纯数字");}else{System.out.println("该字符串不是纯数字");}}}