That will tell you that your () match, but it won't help with this sort of thing.
(1 + 2) * (3 + 4)
You will correctly identify matched () but will incorrectly parse it as if you had one pair of brackets. You need to iterate the
String until you reach the ) which matches your first (.
I cannot remember whether you are pushing and popping in the right places; do you only have one stack? You will have to look in your books for the right way to push and pop ().
In that location, System.exit(0) has no effect at all, but in a multi-threaded application, it might be positively harmful.