Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*****In this program, How can I just print one error only per each array. So, the output I just want to show 5 error only.

*****In this program, How can I just print one error only per each array. So, the output I just want to show 5 error only. each array only print one error message.********** public class Evaluation1 { static int statement = 5; static String[] test = new String[statement]; //array to store the statement test static char[] myStack = new char[40]; static int stackTop; public static void main(String[] args) { test[0] = "{ 1 + 3 ) * ( 2 - 1 )"; test[1] = "( 1 + 3 } * { 2 - 1 )"; test[2] = "{ 1 + 3 ) * ( 2 - 1 )"; test[3] = "{ 1 + 3 * ( 2 - 1 )}"; test[4] = "{ 1 + 3 ) * (2 - 1 }"; for (int i = 0; i < statement; i++) { // loop through how many statement we need to test stackTop = -1; for (int j = 0; j < test[i].length(); j++) { char c = test[i].charAt(j); if (c == '{' || c == '(') { // if char c = { || ( , ( then use push method push(c); } else if ( c =='}' || c == ')') { } switch (test[i].charAt(j)) { case ')': pop(); /* pop ) and } if not match the complete brackets will show error message*/ if ( c != '(' ) System.out.println(test[i]); printErrorMessage(j,3); /* find the location and print correct error message */ break; case '}': pop(); if ( c != '{') System.out.println(test[i]); printErrorMessage(j,1); break; } } } } static void printErrorMessage(int position, int errNo) { String errMsg[] = new String[5]; errMsg[0] = " ( expected"; errMsg[1] = " ) expected"; errMsg[2] = " { expected"; errMsg[3] = " } expected"; for (int i = 0; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

10th Edition

0137916787, 978-0137916788

More Books

Students also viewed these Databases questions