/** * Substring search. */ public class Ex21 { public static void main(String[] args) { System.out.println(substringSearch("able was I ere I saw elba", "ere")); } private static boolean substringSearch(String string, String substring) { boolean found = false; int max = string.length() - substring.length(); test: for(int i = 0; i <= max; i++) { int n = substring.length(); int j = i; int k = 0; while(n-- != 0) { System.out.println("i: " + i + "j: " + j + "k: " + k); if(string.charAt(j++) != substring.charAt(k++)) continue test; } found = true; break; } return found; } }