Print all possible strings
Ex:
abc
ab c
a bc
a b c
/*You have to complete this function*/
class GfG
{
void print(String str,char temp[],int i,int j,int n)
{
if(i==n)
{
temp[j]='\0';
System.out.print(temp);
System.out.print("$");
return;
}
temp[j]=str.charAt(i);
print(str,temp,i+1,j+1,n);
temp[j]=' ';
temp[j+1]=str.charAt(i);
print(str,temp,i+1,j+2,n);
}
void printSpace(String str)
{
char temp[]=new char[str.length()*2];
temp[0]=str.charAt(0);
print(str,temp,1,1,str.length());
}
}
abc
ab c
a bc
a b c
/*You have to complete this function*/
class GfG
{
void print(String str,char temp[],int i,int j,int n)
{
if(i==n)
{
temp[j]='\0';
System.out.print(temp);
System.out.print("$");
return;
}
temp[j]=str.charAt(i);
print(str,temp,i+1,j+1,n);
temp[j]=' ';
temp[j+1]=str.charAt(i);
print(str,temp,i+1,j+2,n);
}
void printSpace(String str)
{
char temp[]=new char[str.length()*2];
temp[0]=str.charAt(0);
print(str,temp,1,1,str.length());
}
}
0 Comments:
Post a Comment