Question: Write a java program to match parenthesis (), square braces [] and curly braces {}. Your program should use a recursive method that returns the
Write a java program to match parenthesis (), square braces [] and curly braces {}. Your program should use a recursive method that returns the number of pairs of each type of brace and return -1 if it is unbalanced for a particular pair. You should also create a Stack class that will be used by the method to match braces. Refer to Chapter 10.6 (page 380) for a sample Stack class.
![Write a java program to match parenthesis (), square braces [] and](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/10/6706a46f84b06_5586706a46ee6347.jpg)
O MatchingBracesTestCases - Notepad File Edit Format View Help (a+b) (a+b*(c-d)) (e+f) (g-h) (a+b*[C-d])[e+f{g-h}] (a+b*[C-d])e+f{g-h}] > run MatchingBraces Enter String: (a+b) Matching () pairs: 1 Matching [] pairs: 0 Matching {} pairs: 0 > run MatchingBraces Enter String: (a+b*(c-d))e+f)(g-h) Matching (0 pairs: 4 Matching [] pairs: 0 Matching {} pairs: 0 > run Matching Braces Enter String: (a+b^[c-d])[erf{g-h}] Matching (1) pairs: 1 Matching [] pairs: 2 Matching {} pairs: 1 > run Matching Braces Enter String: (a+h*[e-d])e+f[g-h} Matching (0 pairs: 1 Unbalanced [] Matching (0 pairs: 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
