Write a static method that will receive two Strings, a needle and a haystack. The method should return true if the needle is found surrounded by parentheses.
Your solution must use either .substring() or .indexOf().
Preconditions:
null and will length 1 or greater.null and will be at least two characters longer than the needle.Examples:
isParenthesized("cat", "(cat)") returns trueisParenthesized("cat", "There's a (cat) here") returns trueisParenthesized("cat", "There's a )cat) here") returns falseisParenthesized("cat", "There's a (dog) here") returns falseisParenthesized("X", "Xx(X)xX") returns true©2003–2016 Graham Mitchell
This assignment is licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States License.
![]()