//package www.JavaDS_Examples.Stack; import java.io.*; /**A class to check for balance in input with respect to characters like '{,(,{' . The class uses stack to find out the correctness of the input . for each character encountered, if it is a opening bracket , it is pushed into the stack .On the other hand if a closing bracket is encountered, the stack is popped and checked for correct opening character . If not found, the algorithm st ops and returns false.*/ public class BalancedBraces { public boolean balanceInput(String input){ /*stack used for manipulating the input */ Stack stack=new ArrayStack(); boolean balancedSoFar=true; // boolean used to check the correctness int i=-1; /*do this while loops, the character we are about to extract is less than the total length and the input is balanced so far*/ while(balancedSoFar && i