print all possible string geeks solution
Problem: input : abc
process like :
abc
ab c
a bc
a b c
Code:
/*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]='$';
for(int p=0;p<=j;p++)
System.out.print(temp[p]);
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)
{
// Your code here
char temp[]=new char[str.length()*2];
temp[0]=str.charAt(0);
print(str,temp,1,1,str.length());
}
}
process like :
abc
ab c
a bc
a b c
Code:
/*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]='$';
for(int p=0;p<=j;p++)
System.out.print(temp[p]);
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)
{
// Your code here
char temp[]=new char[str.length()*2];
temp[0]=str.charAt(0);
print(str,temp,1,1,str.length());
}
}
0 Comments:
Post a Comment