本帖最后由 Papaver_Flower 于 2012-02-16 18:51:15 编辑

解决方案 »

  1.   

    1、难吗?
    2、按题目的要求,你的答案应该是@hjkiiio@jie_nhhhf4
    String x = "_hjk2io_jie@n3hf4_";
    if (x.charAt(x.length() - 1) == '_')
    x = x.substring(0, x.length() - 1);
    char[] temp = x.toCharArray();
    StringBuffer y = new StringBuffer(); for (int i = 0; i < x.length(); i++) {
    if (temp[i] == '_')
    y.append('@');
    else if (temp[i] == '@')
    y.append('_');
    else if (temp[i] >= '0' && temp[i] <= '9' && i < x.length() - 1
    && ('0' < temp[i + 1] || temp[i + 1] < '9'))
    y.append(temp[i + 1]).append(temp[i + 1]);
    else
    y.append(temp[i]);
    }
    System.out.println(y);
      

  2.   

    toCharArray(),转化成char类型数组,然后全数组搜索用for循环,然后找到你要替换的就OK啦
      

  3.   


    public class Test
    {
    public static String change(String str)
    {
    StringBuilder strBuilder = new StringBuilder(str);
    if (strBuilder.charAt(strBuilder.length() - 1) == '_')
    {
    strBuilder.setLength(strBuilder.length() - 1);
    }
    for (int i = 0; i < strBuilder.length(); i++)
    {
    if (strBuilder.charAt(i) == '_')
    {
    strBuilder.setCharAt(i, '@');
    }
    else if (strBuilder.charAt(i) == '@')
    {
    strBuilder.setCharAt(i, '_');
    }
    else if (Character.isDigit(strBuilder.charAt(i)) && i != strBuilder.length() - 1)
    {
    int t = Integer.parseInt(strBuilder.substring(i, i + 1));
    strBuilder.deleteCharAt(i);
    for (int j = 1; j < t; j++)
    {
    strBuilder.insert(i, strBuilder.charAt(i));
    }
    }
    }
    return strBuilder.toString();
    }

    public static void main(String[] args)
    {
    String str = "_hjk2io_jie@n3hf4_";
    System.out.println(change(str));
    }
    }
      

  4.   

    根据题意 修正一下,当然能用上正则能清晰很多,但是我看见正则就头晕 String x = "_hjk2io_jie@n3hf4_";
    if (x.charAt(x.length() - 1) == '_')
    x = x.substring(0, x.length() - 1);
    char[] temp = x.toCharArray();
    StringBuffer y = new StringBuffer(); for (int i = 0; i < x.length(); i++) {
    if (temp[i] == '_')
    y.append('@');
    else if (temp[i] == '@')
    y.append('_');
    else if ((temp[i] >= '0' && temp[i] <= '9')
    && i < x.length() - 1
    && (('a' < temp[i + 1] || temp[i + 1] < 'z') && ('A' < temp[i + 1] || temp[i + 1] < 'Z')))
    y.append(temp[i + 1]).append(temp[i + 1]);
    else
    y.append(temp[i]);
    }
    System.out.println(y);
      

  5.   

    修正一下,当然用上正则能清晰很多,但是我看见正则就头晕! String x = "_hjk2io_jie@n3hf4_";
    if (x.charAt(x.length() - 1) == '_')
    x = x.substring(0, x.length() - 1);
    char[] temp = x.toCharArray();
    StringBuffer y = new StringBuffer(); for (int i = 0; i < x.length(); i++) {
    if (temp[i] == '_')
    y.append('@');
    else if (temp[i] == '@')
    y.append('_');
    else if ((temp[i] >= '0' && temp[i] <= '9')
    && i < x.length() - 1
    && (('a' < temp[i + 1] || temp[i + 1] < 'z') && ('A' < temp[i + 1] || temp[i + 1] < 'Z')))
    y.append(temp[i + 1]).append(temp[i + 1]);
    else
    y.append(temp[i]);
    }
    System.out.println(y);
      

  6.   


    //笨方法,不知正则能不能,待研究
    String x ="_hjk2io_jie@n3hf4_"; 
    System.out.println(x);
    String x1 = x.replace("_","@");
    System.out.println(x1);
    String x2 ="";
    if((char)x1.charAt(x1.length()-1)=='@')
    {
    for(int i=0;i<x1.length()-1;i++)
    {
    x2=x2+x1.charAt(i);
    }
    }
    else
    {
    x2=x1;
    }
    System.out.println(x2);

    String x3 ="";
    int a = 0;
    for(int i=0;i<x2.length();i++)
    {
    if(a>0)
    {
    for(int j=0;j<a;j++)
    {
    x3=x3+x2.charAt(i);
    }
    }
    a = x2.charAt(i);
    if(a>=48 && a <=57)
    {
    a=a-48;
    }
    else
    {
    a=0;
    x3=x3+x2.charAt(i);
    }

    }
    System.out.println(x3);