Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7749479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:03:38+00:00 2026-06-01T11:03:38+00:00

I would greatly appreciate if you could help me with this in Java. Given

  • 0

I would greatly appreciate if you could help me with this in Java.

Given two Strings, lets say String A = "(A+B)+(C)" and String B = "((A+B)+(C))" and String C = (A+B) and String D = A+(B+C) and String E = (A+(B+C))

How can I identify if the String is completely surrounded by parenthesis like String B.

In example: boolean flag(String expr) { //return false if surrounded, else true }

If expr = A, flag would return true

If expr = B, flag would return false

If expr = C, flag would return false

If expr = D, flag would return true

If expr = E, flag would return flase

Sorry if it isn’t clear, but it should work for any String expression:

Assume the expression contains only Digits and Operators and Parenthesis.

Thanks. Appreciate it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T11:03:39+00:00Added an answer on June 1, 2026 at 11:03 am

    You can’t do it* with a regular expression because nested parentheses isn’t a regular language.

    Instead iterate over the string and keep track of the nesting level by counting the number of opening and closing parentheses. For each opening parenthesis add one to the nesting level. For each closing parenthesis subtract one.

    • If you reach zero (or less) before reaching the end of the string, return true.
    • If you reach zero at the end, return false.
    • Anything else is unbalanced parentheses and shouldn’t happen unless your input is invalid.

    Here are some worked examples to demonstrate the principle:

    (A+B)+(C)
    11110        TRUE
    
    ((A+B)+(C))
    12222112210  FALSE
    
    (A+B)
    11110        FALSE
    
    A+(B+C)
    0            TRUE
    
    (A+(B+C))
    111222210    FALSE
    

    *sanely

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Would greatly appreciate it if someone could help me make this work. I'm trying
I am new to writing SQL and would greatly appreciate help on this problem.
Assuming such a query exists, I would greatly appreciate the help. I'm trying to
Any help here would be greatly appreciated. I have this table hospital Nurse |
I would greatly appreciate some help on anyone that has experience in working with
I'm new to C++ programming and would greatly appreciate replies that don't assume much
I'm trying to make a navigation for my website and would greatly appreciate any
I am struggling to carry out the following. Any help would be greatly appreciated.
Finding windows FastCGI help is proving very difficult. Any help would be greatly apprciated.
any help greatly appreciated. Problem: Ubuntu 11.10 not playing nice with Java's JOGL Summary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.