如:String str1 = "aba";
    String str2 = "abbbbv";
其中字符a与str2中的a重复2次,b重复4次,则打印“bbbb”

解决方案 »

  1.   

    ArrayList numList = new ArrayList();
    for(int i = 0 ; i < str1; i++){
    int num = 0;
    string str11 = str1(i,i+1);
     for(int j = 0 ; j < str1; j++){
    string str22 = str1(j,j+1);
    if(str11.equal(str22)){
    num ++;
    }
    numList .add(num);
     }
    }
    然后从numList里面去出来最大值
      

  2.   

    ArrayList numList = new ArrayList();
    for(int i = 0 ; i < str1; i++){
    int num = 0;
    string str11 = str1.subString(i,i+1);
     for(int j = 0 ; j < str1; j++){
    string str22 = str2.subString(j,j+1);
    if(str11.equal(str22)){
    num ++;
    }
    numList .add(num);
     }
    }
      

  3.   

    to:yufanzy909() 
    我不是要求出重复数量,而是要求出重复最多的字符串,如果str1中的字符a与str2中的a重复2次是最多的话,就打印“aa”,如b重复4次,是最多的,则打印“bbbb”
    我的程序是这样,但我感觉应该还有更简单的:
    public static String test(String str1, String str2) {
        Map<String, String> map = new HashMap<String, String>();
        for (int i = 0; i <= str1.length() - 1; i++) {
            String ai = String.valueOf(str1.charAt(i));//获得str1的第一个字符
            for (int j = 0; j <= str2.length() - 1; j++) {
       String aj = String.valueOf(str2.charAt(j));//获得str2的第一个字符
       if (ai.equals(aj)) {//如果两个字符相等,则判断是否已经比较过这个字符
                    if (map.containsKey(ai)) {
      map.put(ai, map.get(ai) + aj);
           } else {
     map.put(ai, ai);
           }
        } 
    }
        }
        Set<String> set1 = map.keySet();
        String max = null;
        for (String key : set1) {
             String temp = map.get(key);
             System.out.println("key == "+key+" value == "+temp);
    if(max != null && max.length() < temp.length()){
        max = temp;
    }else{
        max = map.get(key);
    }
        }
        return max;
    }
      

  4.   

    最后判断长度那儿错了,改正如下
    Set<String> set1 = map.keySet();
      String max = null;
      for (String key : set1) {
        String temp = map.get(key);
        System.out.println("key == "+key+" value == "+temp);
        if(max != null && max.length() < temp.length()){
    max = temp;
        }else if(max == null){//此处增加一个判断
    max = map.get(key);
        }
      }