/* Write a JAVA program for the given string and take another string and check whether the taken string is substring of given string or not.
Given String : google
Input String : gle
Output : gle is the substring of google
*/
Given String : google
Input String : gle
Output : gle is the substring of google
*/
import java.util.Scanner;
class CheckSubstring
{
public static void main(String[] args)
{
String s="google";
Scanner sc=new Scanner(System.in);
System.out.println("Enter an String : ");
String a=sc.next();
boolean flag=false;int len=0;
for(int i=1;i<=s.length()-a.length();i++)
{
for(int j=0;j<a.length();j++)
{
if(a.charAt(j)!=s.charAt(i+j) )
{
len=0;
break;
}
else
len++;
}
if(len==a.length())
{
flag=true;
break;
}
}
if(flag==true)
System.out.println(a+" is the substring of "+s);
else
System.out.println(a+" is not substring of "+s);
}
}
0 Comment to "Write a JAVA program for the given string and take another string and check whether the taken string is substring of given string or not. "
Post a Comment