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
static 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
Get step-by-step solutions from verified subject matter experts
