This code seems straight forward. I'm trying to make sure my parens are balanced. The output from the following is:
Num left parens: 1
Num right parens: 2
Why this result when both values should be 1?
thanx in advance, vasha
import java.util.*;
public class Test{
private static void main (
String[] args){
try{
String s = "(Q AND Q) OR Q";
int iLeft=0;
int iRight=0;
StringTokenizer stLeft = new StringTokenizer(s,"(");
iLeft = stLeft.countTokens();
StringTokenizer stRight = new StringTokenizer(s,")");
iRight = stRight.countTokens();
dbg("Num left parens: "+iLeft);
dbg("Num right parens: "+iRight);
}
catch (Exception ex)
{
dbg("Exception: "+ex);
}
}
private static void dbg(String asMessage)
{
System.out.println(asMessage);
}
}