String formation from substring geeks solution
Problem : Check Whether a string is a formation of its repeated substring
Ex: aaaa
ababab
Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class GFG
{
public static void main (String[] args)
{
Scanner ab=new Scanner(System.in);
int t=ab.nextInt();
while(t-->0)
{
String str=ab.next();
String str2=str+str;
str2=str2.substring(1,str2.length()-1);
if(str2.contains(str))
System.out.println("True");
else
System.out.println("False");
}
}
}
Ex: aaaa
ababab
Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class GFG
{
public static void main (String[] args)
{
Scanner ab=new Scanner(System.in);
int t=ab.nextInt();
while(t-->0)
{
String str=ab.next();
String str2=str+str;
str2=str2.substring(1,str2.length()-1);
if(str2.contains(str))
System.out.println("True");
else
System.out.println("False");
}
}
}
0 Comments:
Post a Comment