Skip to content

Commit 44a61e3

Browse files
committed
Version 1
0 parents  commit 44a61e3

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

String_Matching_Algorithm.java

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package pattern_matching_bruteForce;
2+
3+
public class String_Matching_Algorithm {
4+
public static void main(String[] args) {
5+
String T = "aabbcdabbcay";
6+
String P = "bca";
7+
8+
patternMatch(T, P);
9+
}
10+
11+
public static void patternMatch(String T, String P) {
12+
int n = T.length();
13+
int m = P.length();
14+
boolean patternFound = false;
15+
16+
System.out.println("Position\tMatched Substring");
17+
for (int s = 0; s <= (n - m); s++) {
18+
if (P.equals(T.substring(s, s + m))) {
19+
patternFound = true;
20+
System.out.println(s + "\t\t" + T.substring(s, s + m));
21+
}
22+
}
23+
24+
if (!patternFound) {
25+
System.out.println("Pattern not found");
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)