-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatternsearch.java
More file actions
45 lines (38 loc) · 832 Bytes
/
patternsearch.java
File metadata and controls
45 lines (38 loc) · 832 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.util.*;
class patternsearch
{
public static void main(String v[])
{
String s,s1;
int n,m,i,j,k,c=0;
Scanner d=new Scanner(System.in);
System.out.print("ENTER THE STRING:");
s=d.next();
System.out.print("ENYER THE VALID PATTERN STRING:");
s1=d.next();
n=s.length();
m=s1.length();
if(n>m)
{
for(i=0;i<n;i++)
{
for(j=0,k=i;j<m&&k<n;j++)
{
if(s.charAt(k)==s1.charAt(j))
{
k++;
c++;
}
else
{
break;
}
}
}
if(i<=n)
System.out.println("THE PATTERN IS EXIST");
else
System.out.println("THE PATTERN IS NOT EXIST");
}
}
}