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 true
isParenthesized("cat", "There's a (cat) here")
returns true
isParenthesized("cat", "There's a )cat) here")
returns false
isParenthesized("cat", "There's a (dog) here")
returns false
isParenthesized("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.