Need Help ?

Home / Expert Answers / Other / given-a-list-of-strings-of-bracket-characters-00-the-string-of-brackets-is-balanced-under-the-follow

(Answered): Given a list of strings of bracket characters: 00, the string of brackets is balanced under the fol ...



Given a list of strings of bracket characters: 00, the string of brackets is balanced under the following conditions: 1. It i

Example 1 S = TOC. O, C ALL s[0] rarr 2.0 is an unbalanced string due to the open C. Return false. s(1) rarr 2. (O) is

Each string consists only of the characters (. ). (and). - Each string has fewer than 50 characters. ALI Input Format for Cus

Sample Case o Sample Input o STDIN 2 Function 00 + s = [00), ({0), [(] ({0}) {}( 3 Sample Output 0 5 true true false 6

Autocomplete Disabled 1 > import java.util.*; ... 4 5 // Write your code here. DO NOT use an access modifier in your class de

Given a list of strings of bracket characters: 00, the string of brackets is balanced under the following conditions: 1. It is the empty string. 2. If strings a and bare balanced, then ab is balanced. 3. If string a is balanced, then (a) and (a) are balanced. Write a class that determines whether the brackets in each string are balanced and returns true if the string is balance false if it is not. Example 0 S = ["00", "{0}", "({0})" ] s[0] exhibits condition 2 above."0" and "0" are balanced, so "00" is balanced. Return true. s[1] exhibits condition 3 above. "O" is balanced, so "{0}" is balanced. Return true. s[2] exhibits condition 3 above."0" is balanced, so "{0}" is balanced and "((0))" is balanced. Return true. Example 1 S = ["(", "0", "(", "H") s[O] rarr 2. "O" is an unbalanced string due to the open "C". Return false. s[l) rarr 2. "(0)" is an unbalanced string due to ")" before "[" has been closed. Return false. s[2] rarr 2. "(C, is an unbalanced string because neither "(" is closed. Return false. Example 1 S = TOC. "O", "C" ALL s[0] rarr 2.0 is an unbalanced string due to the open "C". Return false. s(1) rarr 2. (O)" is an unbalanced string due to ")" before "{" has been closed. Return false. s[2] rarr 2. (C, is an unbalanced string because neither "(" is closed. Return false. s[2] rarr 2. "H" is an unbalanced string because ")" comes before a "t" and because the final "{" is not closed. Retur Function Description The provided code contains the declaration for a class named Solution with a main method that does the followi 3 • Creates a Parser object. • Reads an unknown number of strings from stdin. • Passes each string as an argument to the Parser object's isBalanced method and prints value returned by the metho line. Complete the function an isBalanced in the editor below. isBalanced has the following parameter(s): string s: a string of characters to check for balance Returns : bool: a boolean that denotes whether the string is balanced: true if the string is balanced, or false if it is not Each string consists only of the characters (. ). (and). - Each string has fewer than 50 characters. ALI Input Format for Custom Testing Input from stdin will be processed as follows and passed to your Parser.isBalanced method. 1 Each line contains a string to parse. 2 Sample Case 0 Sample Input 0 ???? STDIN Function {}() + s = ['00', '({0}', '{}('] ({0}) {}( 5 6 Sample Output 0 true true false ation 0 Sample Case o Sample Input o STDIN 2 Function 00 + s = ['00)', '({0)', '[('] ({0}) {}( 3 Sample Output 0 5 true true false 6 Explanation 0 2. '00' contains two adjacent balanced strings, 'l 'and 'O' so return true. 3. (CO}}' contains a balanced string ' Onested inside another balanced string, 'f', nested inside another balanced Return true. 2. ' contains a balanced string '/', followed by an unbalanced string '(. Return false. - wa EE DE 6 Autocomplete Disabled 1 > import java.util.*; ... 4 5 // Write your code here. DO NOT use an access modifier in your class declaration. 6 7 v class Solution { 8 9 public static void main(String[] args) { 10 Parser parser = new Parser(); 11 12 Scanner in = new Scanner(System.in); 13 14 while (in.hasNext()) { 15 System.out.println(parser.isBalanced (in.next()); } 16 in.close(); 17 18 19 20 21 } } I Line: 4 col Submit Code Run 12:30


We have an Answer from Expert

View Expert Answer

Expert Answer


Answer to Given a list of strings of bracket characters: 00, the string of brackets is balanced under the following conditions: 1....
We have an Answer from Expert

Buy This Answer $4

Place Order