Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Bracket Checking (Brackets.java) Write a program that examines a string of characters and determines if all opening bracket characters such as (, [, or {

Bracket Checking (Brackets.java)

Write a program that examines a string of characters and determines if all opening bracket characters such as (, [, or { are matched with their correct closing characters. Use a stack to do this. The basic algorithm is as follows:

Read the string, character by character.

If the character is an opening bracket character, push its equivalent closing character onto the stack.

If the character is a closing bracket character, pop the stack, and see if the character you popped matches the current character. If not, the brackets in the string are not paired correctly.

If the character is not a bracket character, ignore it.

If you get through the whole string without failing, check to see if the stack is empty. If it is, the brackets are all matched correctly. If not, the brackets were not matched correctly.

Your program should print a message back to the user if the brackets are correctly matched or not

Test your program on some small strings. Once it is working properly, it should work regardless of the string. Try using it on an entire Java source code file.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions

Question

=+5 How does HRM relate to efforts to increase innovation?

Answered: 1 week ago

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago