Given a String, s, which is assumed to have at least one character in it, which of the following conditions would determine if the first character of the String is the same as the last character?
f) (s.charAt(0) == s.charAt(s.length( )))
g) (s.charAt(1) == s.charAt(s.length( )))
h) (s.charAt(0) == s.charAt(s.length( ) - 1))
i) (s.charAt(0) == s.charAt(s.length( ) + 1))
j) (s.charAt(0) == s.charAt(last))
Answer: c. Explanation: The first character of a String starts at position 0. So, if a String’s length is 5, then its last character is at position 4. Therefore, the last character is at position s.length( ) – 1. The answer in e could be correct, but only if last had been previously set equal to s.length( ) – 1.