1 public class T004 { 2 public static void main(String[] args){ 3 System.out.println(replaceBlank("we are happy")); 4 } 5 public static String replaceBlank(String s){ 6 String r = "%20"; 7 String result = ""; 8 for(int i=0;i<s.length();i++){ 9 if(s.charAt(i)==‘ ‘){ 10 result +=r; 11 }else{ 12 result += s.charAt(i); 13 } 14 } 15 return result; 16 17 } 18 }
java实现——004替换空格,布布扣,bubuko.com
原文:http://www.cnblogs.com/thehappyyouth/p/3714620.html