214k views
5 votes
Need help writing a program that reads a string if the option "E" (enter a string) is chosen, and checks if parentheses (), brackets [], and braces {} are matched in a given string.

Implement this method using a Stack from java.util package.

You can use the string "A" as a token for parentheses, "B" as a token for brackets, "C" as a token for braces.

When an opening parenthesis is read, push the token "A", and when a closing parenthesis is read, pop the token "A" if available.
A similar operation can be done for others. Only if the stack is empty when you finish reading all characters of the string, you can confirm that everything was matched. Otherwise, the method needs to return an appropriate message stated above.

1 Answer

2 votes

Answer:

is this even a question?...

User Yngwaz
by
5.7k points