Can anyone help me for this program? import java.util.Stack; public class Parent
ID: 3539772 • Letter: C
Question
Can anyone help me for this program?
import java.util.Stack;
public class Parentheses
{
// Return true if the parentheses in the specified string are properly
// matched; false otherwise. For example, [()]{}{[()()]()} is properly
// matched while [(]) is not.
public static boolean isValid(String s)
{
// TBD
}
// Test driver.
public static void main(String[] args)
{
System.out.println("Should print true: " +
isValid("[()]{}{[()()]()}"));
System.out.println("Should print false: " +
isValid("[(])"));
System.out.println("Should print true: " +
isValid("[hellp ( world ) !]"));
}
}
Explanation / Answer
public static boolean isValid(String s) { int nesting = 0; for (int i = 0; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.