Problem3_1 { public boolean isBalancedString(final String input) { Stack<Character> stack = new Stack<>(); char[] chars = input.toCharArray(); for (char ch : chars) { if (ch == ')' && !stack.empty()) { stack.pop(); } else { stack.push(ch); } } return stack.isEmpty(); }  boolean isBalancedString(final String input); int firstOffendingParenthesis(String input);  }
@Test public void shouldSayTrueForEmptyString() throws Exception { final String input = ""; boolean balanced = checker.isBalancedString(input); assertTrue(balanced); }
@Test public void shouldSayTrueWhenStringIsBalanced() throws Exception { final String input = "((())())()"; boolean balanced = checker.isBalancedString(input); assertTrue(balanced); }
@Test public void shouldSayFalseWhenStringIsNotBalanced() throws Exception { final String input = ")()("; boolean balanced = checker.isBalancedString(input); assertFalse(balanced); }
@Test public void shouldSayFalseWhenStringIsNotBalanced_anotherInput() throws Exception { final String input = "())"; boolean balanced = checker.isBalancedString(input); assertFalse(balanced); }