title: Finding index where char c starts in string s
body: <p>I am writing a program with many methods for an assignment, and in one of the methods, I need to find the index where character c starts in string s. for example:</p>
  
  <pre><code>IN: sheep, h
  OUT: 1
  </code></pre>
  
  <p>I have done this method but with two strings instead of a string and a character</p>
  
  <pre><code>public static int findInStr1(String s1, String s2) {
      for (int i = 0; i &lt; s1.length() - s2.length(); i++) {
          boolean found = true;
          for (int j = 0; j &lt; s2.length(); j++) {
              if (s1.charAt(i) != s2.charAt(j)) {
                  found = false;
                  break;
              }
          }
          if (found) {
              return i;
          }
      }
      return -1;  
  }
  </code></pre>
  
  <p>I tried to move some things around to make it work with a char instead of a second string</p>
  
  <pre><code>public static int findInStr2(String s1, char c) {
      for (int i = 0; i &lt; s1.length() - 1; i++) {
          boolean found = true;
          if (s1.charAt(i) != c) {
              found = false;
              break;
          }
          if (found) {
              return i;
          }
      }
      return -1;
  }
  </code></pre>
  
  <p>but it always returns -1 no matter the input</p>
  
  <p>Thanks in advance</p>