Plz Help me fix this runtime error :
Q. The question is we have to replace the occurrence of the "ab" with "12" and return the new string and recursion is to be used, so if, the input string is "xabx" the output should be "x12x". public class Replaceab { public static String replaceH(String input,int index,String help){ if(index == input.length()){ return help; } if(input.substring(index,index+2).equals("ab")){ help = help + "12"; return replaceH(input,index+2,help); }else{ help = help + input.substring(index,index+1); return replaceH(input,index+1,help); } } // Return the changed string public static String replace(String input){ if(input.length()==1){ return input; } String help = ""; return replaceH(input,0,help); } public static void main(String[] args) { // TODO Auto-generated method stub String s = "xabx"; s = replace(s); System.out.println(s); /* the ideal output should be x12x but I am getting runtime error */ } }