您的位置:首页 > 其它

实现一个函数把字符串中的每个空格替换成“20%”

2017-08-28 16:10 555 查看

题目:实现一个函数把字符串中的每个空格替换成“20%”。

字符替换问题,replaceAll();方法的使用
输入:"hello  world"
输出:hello20%20%world
java代码如下:
public class Test {
public static void main(String[] args) {
String  string="hello  world";
System.out.println(spaceReplace(string));
}

private static String  spaceReplace(String string) {
// TODO Auto-generated method stub

return string.replaceAll(" ", "20%");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐