1 package 正则; 2 3 public class TestIsNum { 4 public static void main(String[] args) { 5 String s1="abc"; 6 String s2="987652345678009876543211234567890"; 7 String s3="a5678"; 8 String s4="23456789j"; 9 System.out.println(isNums(s1)); 10 System.out.println(isNums(s2)); 11 System.out.println(isNums(s3)); 12 System.out.println(isNums(s4)); 13 System.out.println(isNumsGoodMethod(s1)); 14 System.out.println(isNumsGoodMethod(s2)); 15 System.out.println(isNumsGoodMethod(s3)); 16 System.out.println(isNumsGoodMethod(s4)); 17 18 } 19 public static boolean isNums(String arr){ 20 char[] charArray=arr.toCharArray(); 21 char[] nums={'0','1','2','3','4','5','6','7','8','9'}; 22 for(int i=0;i<charArray.length;i++){ 23 for(int j=0;j<nums.length;j++){ 24 if(charArray[i]==nums[j]){ 25 break; 26 } 27 if(j==nums.length-1){ 28 return false; 29 } 30 } 31 } 32 return true; 33 } 34 public static boolean isNumsGoodMethod(String arr){ 35 char[] charArray=arr.toCharArray(); 36 for(char c:charArray){ 37 if(c>'9'||c<'0') 38 return false; 39 } 40 return true; 41 } 42 }