JAVA question A string may use more than one type of delimiter to bracket information into \"blocks\"....

90.2K

Verified Solution

Question

Programming

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 = \"[{}]\";
    • good
  • String string2 = \"[x{12345}xxx]xxx\";
    • good
  • String string3 = \"[1{2(3)4}5]\";
    • good
  • String string4 = \"[][](){}\";
    • good
  • String string5 = \"[[]}\";
    • bad
  • String string6 = \"[])\";
    • bad
  • String string7 = \"[]123{}123()123[{}]\";
    • good
  • String string8 = \"[[[[[]]]]]((((())))){{{{{{{{{{[]}}}}}}}}}}\";
    • good
  • String string9 = \"[[[[[]]]]]((((())))){{{{{{{{{{[]}}}}}}}}]}\";
    • bad
  • String string10 = \"[{({({({([[]])})})})}][{}]{}{{}}\";
    • good
  • String string11 = \"[{(\";
    • bad
  • String math = \"2+(3+5*(5+7-4)*[1+2+3+(6/5)])/(2*a)\";
    • good

Answer & Explanation Solved by verified expert
4.2 Ratings (552 Votes)
SOLUTION I have solve the problem in Java code with comments and screenshot for easy understanding    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students