(How would I write down this prompt in javascript(code) // YOU DO…
Question Answered step-by-step (How would I write down this prompt in javascript(code) // YOU DO… (How would I write down this prompt in javascript(code) // YOU DO NOT NEED TO IMPORT ANY PACKAGE// USAGE OF EXTRA PACKAGE WILL RESULT 0 IN YOUR GRADEpublic class ValidParentheses{//You will be given an array of characters which only contain ‘(‘ and ‘)’//You need to validate the parentheses:// If there is ‘(‘, there must be ‘)’ but not neccessary right after// ‘(‘ and ‘)’ need to be in correct orderpublic static boolean validateParentheses(char[] parentheses){//TODO: YOUR CODE HERE return false; //Return for compilation, this is wrong -> delete when done} public static void main(String[] args){char[] parentheses1 = {‘(‘, ‘)’};System.out.println(“Test 1 passed: ” + (validateParentheses(parentheses1) == true));System.out.println(“——————-“); char[] parentheses2 = {‘(‘, ‘(‘, ‘)’, ‘)’};System.out.println(“Test 2 passed: ” + (validateParentheses(parentheses2) == true));System.out.println(“——————-“); char[] parentheses3 = {‘(‘, ‘(‘, ‘)’};// this is false because it needds an extra close parenthesis to match the first open parenthesisSystem.out.println(“Test 3 passed: ” + (validateParentheses(parentheses3) == false));System.out.println(“——————-“); char[] parentheses4 = {‘)’, ‘(‘, ‘)’, ‘(‘};// this is false because of a close parenthesis appears before an open parenthesis (first one/index 0)System.out.println(“Test 4 passed: ” + (validateParentheses(parentheses4) == false));System.out.println(“——————-“); char[] parentheses5 = {‘(‘, ‘)’, ‘)’, ‘)’, ‘(‘, ‘(‘};// // this is false because of a close parenthesis appears before an open parenthesis (third one/index 2)System.out.println(“Test 5 passed: ” + (validateParentheses(parentheses5) == false));System.out.println(“——————-“); char[] parentheses6 = {‘(‘, ‘)’, ‘(‘, ‘)’};System.out.println(“Test 6 passed: ” + (validateParentheses(parentheses6) == true));System.out.println(“——————-“); char[] parentheses7 = {‘(‘, ‘(‘, ‘(‘, ‘)’, ‘)’, ‘(‘};// this is false because there is no close parenthesis to match openned ones (first one and sixth one)System.out.println(“Test 7 passed: ” + (validateParentheses(parentheses7) == true));System.out.println(“——————-“);}} Engineering & Technology Computer Science CSC 130 Share QuestionEmailCopy link Comments (0)


