public static boolean testBalance(String s) { charStack stk = new charStack(); boolean okay = true; for (int i=0; okay && (i < s.length()); i++) { char c = s.charAt(i); switch ( c ) { case '(': case '{': case '[': stk.push(c); break; case ')': if ( stk.empty() || ( stk.pop() != '(' ) ) okay = false; break; // same for '}' and ']' default: break; // accept other chars } } return (okay && stk.empty() ); }
Contents    Page-10    Prev    Next    Page+10    Index