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...
Write a program in Java which performs the sort operation. The main method accepts ten numbers...
Write a program in Java which performs the sort operation. The main method accepts ten numbers in an array and passes that to the method sort. The method sort accepts and sorts the numbers in ascending and descending order. The method display shows the result. You can use integers or floating point numbers.
(java) Part 1 Write a method named compare that accepts two String arrays as parameters and...
(java) Part 1 Write a method named compare that accepts two String arrays as parameters and returns a boolean. The method should return true if both arrays contain the same values (case sensitive), otherwise returns false. Note - the two arrays must be the same length and the values must be in the same order to return true. Part  2 Write a method named generateArray that accepts an int size as its parameter and returns an int[] array where each element...
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]
Intermediate Accounting I Ethics Question (20 pts. for content; 10 pts. for communication): Thank you very...
Intermediate Accounting I Ethics Question (20 pts. for content; 10 pts. for communication): Thank you very much! In January 2018, Dunder Mifflin Inc. bought property in downtown Scranton. The property contains land, a warehouse, and some limited equipment. Property values in the area have been increasing rapidly over the past decade. The price paid for the property needs to be allocated to the items purchased and the controller and financial vice president are having that discussion. Dunder Mifflen’s controller wants...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT