Test whether a substring is a part of a string
<p>I made a program to test whether a substring is a part of another string. But it's always returning <code>false</code>.</p>

<pre><code>public class SubString{

    public static void main(String... args){
        String findFrom = "mouse";
        String toFind = "mouse and cat";
        boolean flag = false;
        int toFindLenght = toFind.length();
        int findFromLength = findFrom.length();

        for (int x = 0; x &lt; toFindLenght; x++) {
            char toFindIntermediate = toFind.charAt(x);

            for (int y = 0; y &lt; findFromLength; y++) {
                char toFindFromIntermediate = findFrom.charAt(y);
                int counter = x;
                if (toFindIntermediate == toFindFromIntermediate) {
                    toFindFromIntermediate=toFind.charAt(counter);
                    counter++;

                    flag=true;
                } else {
                    flag=false;
                }
            }
        }

        System.out.println("IS the substring a part of the string :"+flag);
    }
}
</code></pre>
