1 package org.feistymeow.algorithms;
17 if ((x ==
null) || (y ==
null))
19 if (y.length() < x.length())
21 for (
int yIter = x.length() - 1; yIter < y.length(); yIter++) {
29 for (
int xIter = 0; xIter < x.length(); xIter++) {
30 int yComparePosition = (yIter - x.length() + 1) + xIter;
31 if (x.charAt(xIter) != y.charAt(yComparePosition)) {
38 int toReturn = yIter - x.length() + 1;
47 public static void main(String[] argv)
51 String x1 =
"petunia";
52 String y1 =
"sometimes my flowers are roses and sometimes they are petunias and sometimes they are turnips.";
54 System.out.println(
"FAILURE: did not find at right index for test 1");
56 System.out.println(
"OKAY: found substring at right index for test 1");
62 System.out.println(
"FAILURE: did not find at right index for test 2");
64 System.out.println(
"OKAY: found substring at right index for test 2");
70 System.out.println(
"FAILURE: found non-existent string for test 3");
72 System.out.println(
"OKAY: did not find substring for test 3");
static void main(String[] argv)
int findXinY(String x, String y)