/***** Replace each space in the string with % 20. for example, if We are happy, the output We % 20are % 20 happy **/public class ReplaceSpace {public void repalce (char [] oldchar, char [] replacement) {int sumOfSpace = 0; for (int I = 0; I <oldchar. length; I ++) {if (oldchar [I] = '') sumOfSpace ++;} if (sumOfSpace = 0) {return ;} char [] newchar = new char [oldchar. length + (replacement. length-1) * sumOfSpace]; // point to the last element of the replaced string, int pOld = oldchar. length-1; // point to the last element of the replacement string, int pNew = newchar. length-1; while (pNew> = 0) {if (oldchar [pOld] = '') {pOld --; for (int j = replacement. length-1; j> = 0; j --) {newchar [pNew --] = replacement [j] ;}} else {newchar [pNew --] = oldchar [pOld --] ;}}for (char c: newchar) {System. out. print (c) ;}} public static void main (String [] args) {char [] ch = "We are happy ". toCharArray (); ReplaceSpace rs = new ReplaceSpace (); rs. repalce (ch, "% 20 ". toCharArray ());}}