Given the following method:
public boolean check(String s) {
return s.length() >= 2 &&
(s.charAt(0) == s.charAt(1) || check(s.substring(1))); }
This method will return true if and only if:
1. s.charAt(0) == s.charAt(1)
2. s starts with two or more of the same characters
3. s ends with two or more of the same characters
4. s contains two or more of the same characters
5. s contains two or more of the same character in a row
Given public boolean check(String s) { return s.length() >= 2 && (s.charAt(0) == s.charAt(1) || check(s.substring(1))); } s.length() >= 2 means string length should be greater than or equals to 2 s.charAt(0) == s.charAt(1) means the first two characters of the string are same ot check(s.substring(1)) is a recursive call doing same from string except the first character. So, (s.charAt(0) == s.charAt(1) || check(s.substring(1)) checks for character match for the to adjacent characters in the string. So, answer is "s contains two or more of the same character in a row"
s contains two or more of the same character in a row
Get Answers For Free
Most questions answered within 1 hours.