-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNaiveMatcher.java
More file actions
29 lines (28 loc) · 685 Bytes
/
NaiveMatcher.java
File metadata and controls
29 lines (28 loc) · 685 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
import java.util.*;
public class NaiveMatcher
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.println("Enter the Text:");
String text=input.nextLine();
System.out.println("Enter the Pattern:");
String pattern=input.nextLine();
int i,j;
int n=text.length();
int m=pattern.length();
for( i=0;i<=n-m;i++)
{
for(j=0;j<m;j++)
{
if(!(text.charAt(j+i)==pattern.charAt(j)))
break;
}
if(j==m)
{
System.out.println("Pattern found at index: "+ i);
continue;
}
}
}
}