import java.util.*;
public class Main {
public static String duplicate(String str, String ans,int j){
if(j>=str.length())
return (ans);
char c=str.charAt(j);
if(c==str.charAt(j+1)){
ans=ans+str.charAt(j);
return duplicate(str,ans,j+2);}
else{
ans= ans+str.charAt(j);
return duplicate(str,ans,j+1);}
}
public static void main(String args[]) {
try{
Scanner sc=new Scanner(System.in);
String str=sc.nextLine();
System.out.println(duplicate(str," ",0));
}catch(Exception e){System.out.println(e);}}
}what is problem with my code