/* 
* @Author: Beinan
* @Date:   2015-01-08 18:04:08
* @Last Modified by:   Beinan
* @Last Modified time: 2015-01-08 18:27:53
*/

public class StrStr {

    /**
     * @param   source      the string being searched.
     * @param   target      the substring to search for
     * @return  the index of the first occurrence of the specified substring,
     *          starting at the specified index,
     *          or {@code -1} if there is no such occurrence.
     */
    public static int strStr(String source, String target){
      int max = source.length() - target.length();
      for(int i = 0; i <= max; i++){
        int matched_count = 0;
        for(/*nothing*/; 
          matched_count < target.length() 
          && source.charAt(i + matched_count) == target.charAt(matched_count); 
          matched_count++);
        if(matched_count == target.length())
          return i; //matched  

      }
      return -1;
    }
    
    //test script
    public static void main(String[] args) {
      System.out.println(strStr("abcde", "cde"));
      System.out.println(strStr("abcde", "cdef"));       
    }


}
@@ -115,15 +115,15 @@
 08 1
-8:27:53
+9:36:38
 %0A*/%0A
@@ -1095,16 +1095,119 @@
 cdef%22));
+%0A      System.out.println(strStr(%22abcde%22, %22%22));%0A      System.out.println(strStr(%22%22, %22%22));%0A             
        %0A

improve test cases of strstr.java