老师出的题目。本人初学,啥也不会,请大家帮忙!如:
String a="123.45";
要求:
    字符串中的 1 -->a
    字符串中的 2 -->b
    字符串中的 3 -->c
    字符串中的 . -->d
    字符串中的 4 -->e
    字符串中的 5 -->f
大恩不言谢!

解决方案 »

  1.   

    谢谢, 小弟自己写了一个 不知此方法是否是最好的方法!
    try{
    String str = "1234567890.123";
    int num=str.length();
    String[] sn= new String[num];String s="";
    char[] ch = new char[str.length()];
    for(int i = 0; i < str.length(); i++)
    {ch[i] = str.charAt(i);
    if(ch[i]=='1'){
    sn[i]="a";
    }else if(ch[i]=='2'){
    sn[i]="l";
    }else if(ch[i]=='3'){
    sn[i]="f";
    }else if(ch[i]=='4'){
    sn[i]="c";
    }else if(ch[i]=='5'){
    sn[i]="g";
    }else if(ch[i]=='6'){
    sn[i]="w";
    }else if(ch[i]=='7'){
    sn[i]="mh";
    }else if(ch[i]=='8'){
    sn[i]="d";
    }else if(ch[i]=='9'){
    sn[i]="e";
    }else if(ch[i]=='0'){
    sn[i]="n";
    }else if(ch[i]=='.'){
    sn[i]="s";
    }s+=sn[i];
    out.println(ch[i]);
    }
    out.println("<br>"+s);
      
      }catch(Exception e){out.println(e.toString());}
      

  2.   

    中心思想就是
    String a="123.45";
    要求:
        字符串中的 1 -->a
        字符串中的 2 -->b
        字符串中的 3 -->c
        字符串中的 . -->d
        字符串中的 4 -->e
        字符串中的 5 -->f
    因为我不会别的办法呀。所以用这么笨的方式
      

  3.   

    public String replace(char oldChar, char newChar)
      

  4.   

    您好! 原题目是:
    String str = "1234567890.123";
    如何将字符串str中的数字改成对应的字母?
    如:1-->a,2-->b……
    输出结果为:"abcd……"
    基本上就这个样子
      

  5.   

    中心思想就是
    String a="123.45";
    要求:
        字符串中的 1 -->a
        字符串中的 2 -->b
        字符串中的 3 -->c
        字符串中的 . -->d
        字符串中的 4 -->e
        字符串中的 5 -->fa = a.replaceAll("1","a").replaceAll("2","b").replaceAll("3","c").replaceAll(".","d").replaceAll("4","e").replaceAll("5","f");
      

  6.   

    大概说说我的思路:用一下asc码,但数字到字母要加多少不记得了,还有可能.需要另外处理
    String str = "1234567890.123";
    char oldChar;
    char newChar;
    for(int i=0;i<10;i++){
      oldChar = i;//进行一下类型转换
      newChar = oldChar + ..// asc码转换
      str = str.replace(oldChar,newChar);
    }
    System.out.print(str);
      

  7.   

    是要输出"abcdefghijklmn"这个字符串吗?
      

  8.   

    public class changeNum1

      public static void main(String args[])
      {
       int i;
       String str[]={"a","b","c","d","e","f"};
       String a="123.45"; 
       String s="";
       System.out.println("您输入的字符是"+a);
       for(i=0;i<a.length();i++)
       { s=s+str[i];}
       System.out.println("转换后的字符是"+s); 
      }
    }
      

  9.   

    a = a.replaceAll("1","a").replaceAll("2","b").replaceAll("3","c").replaceAll(".","d").replaceAll("4","e").replaceAll("5","f");
      

  10.   

    String a="123.45";
    要求:
    字符串中的 1 -->a
    字符串中的 2 -->b
    字符串中的 3 -->c
    字符串中的 . -->d
    字符串中的 4 -->e
    字符串中的 5 -->f您好! 原题目是:
    String str = "1234567890.123";
    如何将字符串str中的数字改成对应的字母?
    如:1-->a,2-->b……
    输出结果为:"abcd……"
    基本上就这个样子=======================
    好像没让你换“.”吧。
      

  11.   

    如 beconcon() 所说的做。就OK了。
      

  12.   

    String str = "1234567890.123";
    for(int i=0;i<str.length;i++){
      if(str[i]>='0'&&str[i]<'9')
        str[i]='a'-'0';
    }
    这样就把str中的数字转化为字符了
    现在的对应规则是 0->a 1->b....
    要改的话只要把str[i]='a'-'0'的两个字符替换就可以了
      

  13.   

    错了一点
    String str = "1234567890.123";
    for(int i=0;i<str.length;i++){
      if(str[i]>='0'&&str[i]<'9')
        str[i]+='a'-'0';
    }
    这样就把str中的数字转化为字符了
    现在的对应规则是 0->a 1->b....
    要改的话只要把str[i]+='a'-'0'的两个字符替换就可以了
      

  14.   

    if  else  可以吗?
      

  15.   

    swich开关语句看起来比较好~~
      思路就是上面各位所说的`~呵可~