Description Title:
Please implement a function, a string to replace each space to "20%." For example, when the string is We Are Happy. After the string is replaced after We% 20Are% 20Happy.
public class Solution { // use StringBuilder transform public String replaceSpace (the StringBuffer STR) { StringBuilder S = new new StringBuilder (); // to return results for ( int I = 0; I <str.length (); I ++ ) { IF (str.charAt (I) == '') { // if it is replaced with spaces s.append ( "% 20 is" ); } the else { s.append (str.charAt (I)); // not spaces, without replacing } } return s.toString (); // return result } }
String, StringBuilder calculated length by length () method.