Question: Write a Java application to open any text file, then to read the entire file character by character and use a stack of characters to

Write a Java application to open any text file, then to read the entire file character by character and use a stack of characters to either output an error message if parens, brackets and curly braces are not properly nested, or a message stating that the file is correct if all of those symbols are properly nested. The basic idea is to push left parens, left brackets and left curly braces onto the stack, then to pop the stack when a right paren, right bracket or right curly brace is encountered and make sure the two symbols match.

Be sure to output appropriate, different, error messages if the left symbol from the stack does not match the right one, if the stack is empty when you need to pop it, and if the stack is not empty when the input is complete.

Note that a Java program that compiles will be correct if there are no parens, brackets or braces in quotes or comments

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!