JAVA question
A string may use more than one type of delimiter to bracketinformation into \"blocks\". The primary ways to divide things upinto block is by the braces { } , parentheses ( ), and brackets [ ]as delimiters.
- A string is considered properly delimited if each rightdelimiter ] } or )( is matched with a preceding left delimiter { [( of the same type in such a way that either the resulting blocksof information are disjoint or one of them is contained nestedwithin the other. Â
- Write a method that accepts a string in as a parameter andreturns back a boolean value determining if the string is properlydelimited.
- Read the string char by char, ignoring all symbols but the[,{,(,},)]. Symbols.
- if it is an open delimiter add it to the stack
- if it is a close delimiter check two things
- is the stack empty?
- is the top of the stack the correct open type.
- At the end of the string, if you haven't already returned ananswer
- Check that the stack is empty.
- Use a single stack to check whether a string containingbrackets is or is not properly delimited.
- Test your method on the following strings:
- String string1 = \"[{}]\";
- String string2 = \"[x{12345}xxx]xxx\";
- String string3 = \"[1{2(3)4}5]\";
- String string4 = \"[][](){}\";
- String string5 = \"[[]}\";
- String string6 = \"[])\";
- String string7 = \"[]123{}123()123[{}]\";
- String string8 = \"[[[[[]]]]]((((())))){{{{{{{{{{[]}}}}}}}}}}\";
- String string9 = \"[[[[[]]]]]((((())))){{{{{{{{{{[]}}}}}}}}]}\";
- String string10 = \"[{({({({([[]])})})})}][{}]{}{{}}\";
- String string11 = \"[{(\";
- String math = \"2+(3+5*(5+7-4)*[1+2+3+(6/5)])/(2*a)\";