比如:输入  String str="abc ace cet";
     输出  String str="abcet"

解决方案 »

  1.   

    好像题目和题意不符。
    怎么获得重复的个数,====遍历 +Map
      

  2.   

    提供一个算法:
    遍历字符串查找出重复的字符 然后替换除第一个之外的其他重复字符为空
    最后把空格全部替换掉--->str.replaceAll(" ", "")
      

  3.   

    内容写错了,就是String str="abc acf bfe",输出的是重复字符的个数。
      

  4.   

        public static void counts(String str) {
            int[] nums = new int[26];
            for(char i : str.toCharArray()) {
                if (i < 97 || i > 123) continue;
                nums[i - 97] = nums[i - 97] + 1;
            }        for (int i = 0; i < nums.length; i++) {
                System.out.println((char)(97+i) + ":" + nums[i]);
            }
        }
     //test:
            String str="abc ace cet";
            counts(str);
     //result:
        a:2
    b:1
    c:3
    d:0
    e:2
    f:0
    g:0
    h:0
    i:0
    j:0
    k:0
    l:0
    m:0
    n:0
    o:0
    p:0
    q:0
    r:0
    s:0
    t:1
    u:0
    v:0
    w:0
    x:0
    y:0
    z:1
    a:2
    b:1
    c:3
    d:0
    e:2
    f:0
    g:0
    h:0
    i:0
    j:0
    k:0
    l:0
    m:0
    n:0
    o:0
    p:0
    q:0
    r:0
    s:0
    t:1
    u:0
    v:0
    w:0
    x:0
    y:0
    z:1