1. Engineering
  2. Computer Science
  3. in java...

Question: in java...

Question details
In java
PART III: Matching Parentheses Write a program that takes a string of parentheses, curly-braces and brackets and determines if the parentheses, curly-braces and brackets all match correctly. Two symbols match if there is a closing symbol for every open sym be properly nested. For example, [((O;])) is a properly nested string with matching symbols For example, [W has matching symbols...but not properly nested. For example, ( has properly nested symbols...but not matching symbols Heres the algorithm you must follow (which uses as stack of characters) bol. The symbols must also Traverse the string of symbols Every time you encounter an open symbol, push it onto the stack symbol from the stack the close symbol Every time you encounter a close symbol, pop a f the popped open symbol does not correspond to the string is not valid If the stack is empty when you complete the string traversal, the string is valid Otherwise, the string is not valid. You can treat a string like an array of characters by using the String classs charAt0 method. Just provide the index of the character you want as a parameter and the method will return the character. For example, the following prints the first character in the string named s: System.out.println(s.charAt(0)); Note that this method returns a char, not a string. The String class has a length) method that returns the number of characters in the string
Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution