Question #3 ------------ // Return a string that is equal to the given string s with all occurrences of pat //replaced by new. public static String substitute(String s, String pat, String newS) { String t = ””; // Result so far. int p; // Location of leftmost occurrence of pat in s, or –1 if none. p = s.indexOf (pat); while (p!=-1) { t = t+s.substring(0,p) + newS; s = s.substring( p + pat.length(), s.length()); p = s.indexOf(pat); } return t+s ; }