Question: JAVA QUESTION - BalancedParentheses Implement the class BalancedParentheses with a method isBalanced that receives a String and checks whether the brackets in it are balanced.

JAVA QUESTION - BalancedParentheses

Implement the class BalancedParentheses with a method isBalanced that receives a String and checks whether the brackets in it are balanced.

import java.util.Scanner;

public class BalancedParentheses {

public static void main(String[] args) {

checkParentheses("((a + b) * t/2 * (1 - t)");

checkParentheses("(a + b) * t)/(2 * (1 - t)");

checkParentheses("a + ((a + b) * t)/(2 * (1 - t))");

System.out.println("Enter an expression: ");

Scanner scanner = new Scanner(System.in);

String s = scanner.nextLine();

checkParentheses(s);

}

public static void checkParentheses(String s) {

System.out.println(s + " is "

+ (isBalanced(s) ? "" : "not ")

+ "parentheses balanced");

}

public static boolean isBalanced(String s) {

// INSERT YOUR CODE HERE

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!