I wrote same program but showing error, please review

import java.util.ArrayList;
public class Main
{
static void printsub(String str,String res)
{
if(str.length()==0)
System.out.print(res +"" , “”);

    printsub(str.substring(1),res);
    printsub(str.substring(1),res+str.charAt(0));
}
public static void main(String[] args) 
{
	printsub("abc","");
}

}

@tishachhabra2702_8fc5a68a2e295e35 In the basecase when str.length()==0 you have to print the result and return from the function otherwise you will get IndexOutOfBound Exception. So in the base add a return statement. One more thing that you have to do is Your SysO statement is not correct due to two times Double quote. So write like this :

Corrected Code :

import java.util.ArrayList;
public class Main
{
static void printsub(String str,String res)
{
if(str.length()==0){
System.out.print(res+", ");
return;
}

    printsub(str.substring(1),res);
    printsub(str.substring(1),res+str.charAt(0));
}
public static void main(String[] args) 
{
	printsub("abc","");
}
}

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.