Writing a method to see if String x contains letter "G" : <p>I'm working on an assignment that has us fill in 8 different methods. For the particular method I'm working on, I have to see if the string contains the letter 'G' and return. I came up with something I thought would work but it isn't. Also this is a basic Java class and I'm pretty new so please explain what you did.</p>

<pre><code>/**
 * Where is the location of the letter G (upper or lower case) in
 * the given string?
 * @param x String to check
 * @return 0 based location of first occurrence of G in x,
 *         -1 if G is not present.
 */
public static int indexOfG( String x ) {
    char[] array = x.toCharArray();
    for(int i = 0; i &lt; array.length; i++){
        if(array[i] == 'G'){
            return i ;
        }   
    }
}
</code></pre>
