日期:2014-05-18  浏览次数:20761 次

请教String 替换问题!
老师出的题目。本人初学,啥也不会,请大家帮忙!

如:
String   a= "123.45 ";
要求:
        字符串中的   1   --> a
        字符串中的   2   --> b
        字符串中的   3   --> c
        字符串中的   .   --> d
        字符串中的   4   --> e
        字符串中的   5   --> f


大恩不言谢!

------解决方案--------------------
来csdn找保姆?
------解决方案--------------------
感觉有点奇怪,这样转换有什么意义啊?
------解决方案--------------------
你想要输出的是什么呀?没有看懂你的意思
------解决方案--------------------
晕,源题呢?
------解决方案--------------------
public String replace(char oldChar, char newChar)
------解决方案--------------------
中心思想就是
String a= "123.45 ";
要求:
字符串中的 1 --> a
字符串中的 2 --> b
字符串中的 3 --> c
字符串中的 . --> d
字符串中的 4 --> e
字符串中的 5 --> f

a = a.replaceAll( "1 ", "a ").replaceAll( "2 ", "b ").replaceAll( "3 ", "c ").replaceAll( ". ", "d ").replaceAll( "4 ", "e ").replaceAll( "5 ", "f ");
------解决方案--------------------
大概说说我的思路:用一下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);
------解决方案--------------------
要求说的不清楚
------解决方案--------------------
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);
}
}
------解决方案--------------------
a = a.replaceAll( "1 ", "a ").replaceAll( "2 ", "b ").replaceAll( "3 ", "c ").replaceAll( ". ", "d ").replaceAll( "4 ", "e ").replaceAll( "5 ", "f ");


------解决方案--------------------
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…… "
基本上就这个样子

=======================
好像没让你换“.”吧。
------解决方案--------------------
如 beconcon() 所说的做。就OK了。。。。
------解决方案--------------------