public static void main(String[] args) {String str = "测试12345"; // 测试字符串boolean allDigits = true;int count = 0;for (int i = 0; i < str.length(); i++) {if (Character.isDigit(str.charAt(i))) {count++;}}System.out.println("字符串 '" + str + "'中有 " + count + " 个数字");}