isBalanced

Category: Programming
Author: Benson Limketkai
Book Chapter: 4.2
Problem: isBalanced
Write a static method named isBalanced that accepts a String of parentheses and returns whether the parentheses in the String are balanced or not. To be balanced:

Every opening parenthesis must have a matching closing parenthesis after (to the right of) it.
Every closing parenthesis must have a matching opening parenthesis before (to the left of) it.

You may assume that the String parameter only has opening and closing parentheses.

Here are some example calls to the method:

 Call                      | Returns
--------------------------------------
 isBalanced("")            | true
 isBalanced("()")          | true
 isBalanced("(")           | false
 isBalanced(")")           | false
 isBalanced("()(())")      | true
 isBalanced("(())(())()")  | true
 isBalanced(")()(")        | false
 isBalanced(")(")          | false
 isBalanced("())")         | false
 isBalanced("((())")       | false
 isBalanced("(())")        | true

Hint: You will want to do some counting.