string.indexOf("3")
会返回 3 的位置 如果没有就返回 -1
你可以用一个递归 判断是否还有 3 ,直到把所有的 3 都找出来

解决方案 »

  1.   

    用循环啦
    indexOf(String str, int fromIndex)
    每找到一个字符,就把indexof的返回值付给 fromIndex     
    直到indexof的返回值为-1为止
      

  2.   

    用indexof不如用charAt()呢
    String src = "123456789045356457";
    int count = 0;
    for(int i=0;i<src.length();i++){
      if(src.charAt(i)=='3')
        count++;
    }
    return count; //it's what you want
      

  3.   

    人家还想知道他们的位置呢。
    String src = "123456789045356457";
    int count = 0;
    int length = src.length();
    int position[] = new int[length];
    for(int i=0;i<length;i++){
      if(src.charAt(i)=='3'){
        position[count] = i;
        count++;
      }
    }
    得到的count就是个数,position[0]—position[count]就是他们的位置。