title: Improving my Java method containsSubstring(s1, s2) which finds if s2 is a substring of s1
body: <p>I am a college student that was recently interviewed for an internship position. One of the things asked of me was to write a method that took two Strings as input and returned true if the second argument was a substring of the first. The answer I turned in wasn't satisfactory to me, so while I was driving home I thought of the following solution: </p>
  
  <pre><code>// containsSubstring(s1,s2) returns true if the string s2 is contained within s1
  public static boolean containsSubstring(String s1, String s2) {
  
      if(s2.length()==0 &amp;&amp; s1!=null)
          return true;
  
      for(int i=s2.length()-1;i&lt;=s1.length()-1;i++) {
          if(s2.charAt(s2.length()-1) == (s1.charAt(i))) {
              int k=i;
              for(int j=s2.length(); j&gt;0;j--) {       
                  if(s1.charAt(k) != s2.charAt(j-1))
                      j=-1; // exits loop.
                  else if (j == 1)
                      return true;
                  else
                      k--;
              }
          }
      }
  
      return false;
  }
  </code></pre>
  
  <p>This code basically checks to see if the last character of s2 is equal to the current index of s1 and if so, loops backward through both to see if they match exactly. </p>
  
  <p>Two things I like about this solution are that if s2.length() > s1.length(), the loop won't execute and the method will just return false and also that it doesn't have to check every character in s1 to find the answer.</p>
  
  <p>Are there any improvements I could make in terms of readability, methodology, better programming practices, etc.?</p>