Regarding duplicate character fformatting

Same code is runing in eclipse but in this ide it is showing String indexed out of bound exception

import java.util.Scanner;

public class recursiondu {

public static void main(String[] args) {
	// TODO Auto-generated method stub
   Scanner s=new Scanner(System.in);
   
     
	String str="";
	if(s.hasNextLine()) {
   str=s.nextLine();
	}
	char a=0;
	
	  if(s.hasNextLine()) { a=s.nextLine().charAt(0); }
	 
	StringBuffer sb=new StringBuffer(str);
	string(sb,0,a);
	show( sb);
	
	
}



public static void string(StringBuffer  sb,int i,char a) {
	if(sb.length()-1==i ) {
		return;
	}

	
	
	if(sb.charAt(i)==sb.charAt(i+1)) {
		sb.insert(i+1,a);
	
	}
	
	string(sb,i+1,a);
	//System.out.println(a);
}

public static void show(StringBuffer a) {
	System.out.println(a);
}

}

so a dry run for hello…its output should be hel*lo…but nowhere in the code you have added * in your ans…

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.