package offer;public class Problem04 { /** * 把字符串中的每个空格替换成“%20”。例如:输入“We are happy”,则输出“We%20are%20happy”。 */ public static void main(String[] args) { String str = "We are happy"; System.out.println(str.replace(" ", "%20")); }}
private static String replaceMethod(String s) { StringBuffer buffer=new StringBuffer(); if(s!=null){ for(int i=0;i