I want to do some char matching using a stack and another by recursion. And the program will read any number of quoted string from standard-in and output to standard-out the results, good or bad, for each string. Someone recommended java tokenize the input stream, but i have no idea how to do that. I'm not really sure what or how I do this, other than when the program is given a string input, it will match certain chars (in this case, parenthesis, and will output good or bad.
--- basically: if there are the appropriate number of parentheses (closed and open), and prints good if the string has the corrent amount, and bad if too many closed or open or w/e. ---
ex:
input:
?ab(cde(fghijk)lm{nopq[r]stu}wxy)z?
?ab(cde(fghijk)lm{nopqrstu}wxyz?
?ab(cde(fghijk)lm{no(pq[r]stu}w)xy)z?
output:
Using stack:
good
bad
bad
Using recursion:
good
bad
bad
If someone can explain how to do this, much oblidged. I know very little java, so java-jargon doesn't help me much 😛
--- basically: if there are the appropriate number of parentheses (closed and open), and prints good if the string has the corrent amount, and bad if too many closed or open or w/e. ---
ex:
input:
?ab(cde(fghijk)lm{nopq[r]stu}wxy)z?
?ab(cde(fghijk)lm{nopqrstu}wxyz?
?ab(cde(fghijk)lm{no(pq[r]stu}w)xy)z?
output:
Using stack:
good
bad
bad
Using recursion:
good
bad
bad
If someone can explain how to do this, much oblidged. I know very little java, so java-jargon doesn't help me much 😛