public static int countCharNumbers(String str, int index){ if(str == null || index < 0) throw new IllegalArgumentException("输入的参数不合法!"); char c = str.charAt(index); int count = 0; for(int i = 0; i < str.length();){ int j = str.indexOf(c, i); if(j < 0){ break; }else{ count++; i = j + 1; } } return count; }