id/email
password
forgot password | create account
about | help | prefs
ReadingBatcode reading practice

 

 

Warmup 1Searching4

prev  |  next  |  chance

Notice the lack of curly braces inside the embedded for loop.

public static boolean search(String a, String b, String c) {
    int len = c.length();

    for (int i = 0; i <= a.length() - len; i++)
        if (a.substring(i, i + len).equals(c))
            for (int j = 0; j <= b.length() - len; j++)
                if (b.substring(j, j + len).equals(c))
                    return true;
    return false;
}
Function Call  Return Value
search("Bohemian", "Rhapsody", "pa")
search("Hello", "World", "!")
search("Ok", "Then...", "...")
search("Computational", "Thinking", "Hi")
search("Hello", "World", "e")
search("!!", "??", "aaaa")

Experiment with this code on Gitpod.io

⬅ Back