Question

In: Computer Science

Question 6 20 pts Compose the body of the following Java method: /* * Accepts an...

Question 6 20 pts

Compose the body of the following Java method:

/*
 * Accepts an array of Character consisting of "{[()]}" characters and 
 * returns true if all pairs of parentheses match.  Returns false if
 * parenthesis expression is malformed. Braces are allowed to occur 
 * inside brackets, and brackets are allowed to occur inside parentheses. 
 */

public boolean parenthesesMatch(Character [] input)
{

Solutions

Expert Solution

/*If you any query do comment in the comment section else like the solution*/

public boolean parenthesesMatch(Character [] input) 
        {
                Stack<Character> stack = new Stack<Character>();
                for (int i = 0; i < input.length; i++) 
                {
                        char c = input[i];
                        if (c == '(' || c=='{' || c=='[' ) {
                                stack.push(c);
                        }
                        else if (c == ')' ||c== '}' || c==']') 
                        {
                                if (stack.size() == 0) 
                                {
                                        return false;
                                }
                                char p = stack.pop();
                                if (p == '(' && c==')' || p=='{' && c=='}' || p=='[' && c==']') 
                                {
                                        continue;
                                }
                                else
                                return false;
                        }
                }
        
                if (stack.size() != 0) {        
                        return false;
                }       
                return true;
        }

Related Solutions

Write one Java program and satisfy the following requirements: Write a method called cube that accepts...
Write one Java program and satisfy the following requirements: Write a method called cube that accepts one integer parameter and returns that value raised to the third power. Write a method called randomNumber that returns a random floating-point number in the range of [-20.0, 50.0). (hints: use Random class in the method) Write a method called findMax that accepts three floating-point number as parameters and returns the largest one.(hints: use conditional statement in the method) Overload findMax that accepts one...
3. Write a java method that accepts a binary number and converts it to decimal then...
3. Write a java method that accepts a binary number and converts it to decimal then display the result. For Example: (110)2 = (6)10 (2 2 *1)+ (21 *1) + (20*0) = 6 Additional task: write a method that accepts a decimal and converts it to binary. i need to solve it as soon as and i will upvote you directly
Code in Java Write a recursive method, reverseString, that accepts a String and returns the String...
Code in Java Write a recursive method, reverseString, that accepts a String and returns the String reversed. Write a recursive method, reverseArrayList, that accepts an ArrayList of Strings and returns the ArrayList in reserve order in reserve order of the input ArrayList. Write a main method that asks the user for a series of Strings, until the user enters “Done” and puts them in an ArrayList. Main should make use to reverseArrayList and reverseString to reverse each String in the...
In java Write a static method named consecutiveDigits that accepts an integer n as a parameter...
In java Write a static method named consecutiveDigits that accepts an integer n as a parameter and that returns the highest number of consecutive digits in a row from n that have the same value. For example, the number 3777785 has four consecutive occurrences of the number 7 in a row, so the call consecutiveDigits(3777785) should return 4. For many numbers the answer will be 1 because they don't have any adjacent digits that match. Below are sample calls on...
java/netbeans Write a recursive method, reverseString, that accepts a String and returns the String reversed. Write...
java/netbeans Write a recursive method, reverseString, that accepts a String and returns the String reversed. Write a recursive method, reverseArrayList, that accepts an ArrayList of Strings and returns an ArrayList in reserve order of the input ArrayList. Write a main method that asks the user for a series of Strings, until the user enters “Done” and puts them in an ArrayList. Main should make use to reverseArrayList and reverseString to reverse each String in the ArrayList and then reverse the...
Question 216 pts (TCO 6) Which of the following is used in processing ECG outputs to...
Question 216 pts (TCO 6) Which of the following is used in processing ECG outputs to determine heart rate? QR-interval RR-interval RT-interval SS-interval Flag this Question Question 226 pts (TCO 6) Permanent storage of measurements in a medical device utilizes which type of memory? DRAM SRAM Flash RAM RDRAM Flag this Question Question 236 pts (TCO 6) Microshock is a low-value current (microamps), which passes arm-to-arm through the body by skin contact with a voltage source. a low-value current (microamps),...
6.         Question 6 [Total: 20 marks]                             &
6.         Question 6 [Total: 20 marks]                                                     Please discuss how “variation margin” and “margin call” are related in the context of daily settlement procedure.                                                                                [10 marks] b) What are the most important aspects of the design of a new futures contract?      [10 marks]
Design a Geometry class with the following methods: * A static method that accepts the radius...
Design a Geometry class with the following methods: * A static method that accepts the radius of a circle and returns the area of the circle. Use the following formula: Area=?r^2 * A static method that accepts the length and width of a rectangle and returns the area of the rectangle. Use the folliwng formula: Area = Length x Width * A static method that accepts the length of a triangle's base and the triangle's hight. The method should return...
The program should be able to do the following: In Java accepts one command line parameter....
The program should be able to do the following: In Java accepts one command line parameter. The parameter specifies the path to a text file containing the integers to be sorted. The structure of the file is as follows: There will be multiple lines in the file (number of lines unknown). Each line will contain multiple integers, separated by a single whitespace. reads the integers from the text file in part a into an array of integers. sort the integers...
(20 pts) Using your programming language of choice (from C++, Java, or Python) , also drawing...
(20 pts) Using your programming language of choice (from C++, Java, or Python) , also drawing on your experience from program 1, read an integer, n from keyboard (standard input). This integer represents the number of integers under consideration. After reading that initial integer in, read n integers in, and print the minimum and maximum of all the integers that are read in. Example: Input Output 7 1 5 3 6 9 22 2 Min: 1 Max: 22 C++ preferred
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT