Maam when I try to run this code here it shows indexOutOfBound Exception whereas it is working properly in eclipse .
Please help
Maam when I try to run this code here it shows indexOutOfBound Exception whereas it is working properly in eclipse .
Please help
Scanner scanner = new Scanner(System.in);
String str = scanner.nextLine();
duplicateChar(str,"");
}
public static void duplicateChar(String str,String result) {
if(str.length()==0) {
System.out.println(result);
return;
}
char ch = str.charAt(0);
String ros = str.substring(1);
if(ros=="") {
duplicateChar(ros,result+ch);
}else if(ch==ros.charAt(0)) {
String val = ros.substring(1);
duplicateChar(val,result+ch);
} else {
duplicateChar(ros,result+ch);
}
}
}