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);
}
}