:)PLEASE RESPECT MY THREAD..Thank you for sharing your time and effort..thanks to the code

Java Experts can you share to me some codes or program that will determine VALID or INVALID using the parenthesis symbol() inputs.
The code must use Stack
and it also tell what is the cause why is it invalid is it excess in open parenthesis (...or close parenthesis...)

(this is the sample output)

Enter a string: ()()

Enter a string: (()
excess open parenthesis

Enter a string: (()) ()

Enter a string: ()(())())
excess close parenthesis

Hope you will help me...no bad words please:(:'(

to keep DaniWeb a student-friendly place to learn, don't expect quick solutions to your homework. We'll help you get started and exchange algorithm ideas, but only if you show that you're willing to put in effort as well.


Assuming you have this: "((a<b)&&(c<d))"

Start by looping the String (check the String class API, use the methods, length, charAt() )
Write a loop and take each character of the String using the charAt method.

In the loop.
Whenever you find a '(' put it into the stack. Whenever you find a ')' remove the previous '(' from the stack. If the stack is empty and you can't remove then INVALID.
Ignore all the other characters.

After the loop check the stack.
If it is empty then the String is VALID.
If it still has elements, then INVALID

You can write your own stack, or use the one that java provides for you. Check at the API of the java.util package for the Stack class.

Member Avatar

Read what javaAddict said. Assuming you have at least a basic knowledge of how stacks work, that is the solution. All that's left is for you to implement it.

Then do some studying and check the API of the classes I suggested. I don't know if you have to implement your own stack class, but java provides one for you.
You should have been taught by now how to create instances of those classes and call their methods.

Stepping back: do you know what a Stack is and what operations it supports?