We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f520c2e commit 99985d2Copy full SHA for 99985d2
Basic programs/StringMatching.java
@@ -0,0 +1,32 @@
1
+package BasicPractice;
2
+
3
+public class StringMatching {
4
5
+ public static void main(String[] args) {
6
7
+ String input = "abcdyesefg";
8
+ String output = "yes";
9
10
+ System.out.println(searchString(input, output)); // 4
11
+ System.out.println(searchString(input, "yeb")); // -1
12
+ }
13
14
+ public static int searchString(String input, String output) {
15
16
+ int inplen = input.length();
17
+ int oplen = output.length();
18
19
+ if (inplen == 0 | oplen == 0 | oplen > inplen) {
20
+ return -1;
21
22
23
+ for (int index = 0; index < inplen - oplen; index++) {
24
+ String possibleStr = input.substring(index, index + oplen);
25
+ if (possibleStr.equals(output)) {
26
+ return index;
27
28
29
30
31
32
+}
0 commit comments