Question: Java. Complete the program to check for balanced parentheses in an expression and display the error. import java.util.*; public class BalancedParentheses{ static HashMap errorMsg =

Java. Complete the program to check for balanced parentheses in an expression and display the error.

import java.util.*;

public class BalancedParentheses{

static HashMap errorMsg = new HashMap();

static HashMap pairs = new HashMap();

static String[] Statement = {"( 9 + 8 ) * ( 6 - 2 }"};

public static void main(String[] args){

lErrorMsg();

lPair();

for (int i = 0; i < Statement.length; i++){

System.out.println(Statement[i]);

for (int n = 0; n < Statement[i].length(); n++){

if (Statement[i].charAt(n) == '(' || Statement[i].charAt(n) == '{') {

st.push(Statement[i].charAt(n));

}

//Continue

}

}

}

public static void lErrorMsg(){

errorMsg.put(1, "Syntax Error: Unpaired paranthesis )");

}

public static void lPair(){

pairs.put('(', ')');

pairs.put('{', '}');

}

public static void printError(int location, int errorNumber){

System.out.println("^");

}

}

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!