Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to make this accept negative digits, but I keep on getting the error belo

ID: 3839475 • Letter: I

Question

I need to make this accept negative digits, but I keep on getting the error belown when I do so. Any idea how to make the input "-8+4" work?

Enter an infix expression to convert 8+4 Exception in thread "main" java util -EmptystackException at java util. Stack -peek (Stack java:102) at java util. Stack-pop (Stack -java: 84) at int opost-InToPost-postfixEvaluate (InToPost-java 28) at intopost.InToPost -main InToPost-java:134 C: Use Kevin MAppDataLocal NetBeansCache Mex cutor snippets run.xml.:53: Java returned 1 BUILD FAILED total time: 5 seconds

Explanation / Answer

I can see the genarated Postfix expression is wrong. ...You need to differentiate between the regular - (minus ) sign like


a - b

AND

-a+b

Here minus is of a and not the expression..We need to distinguish that part and if we are able to then code will work.


Code is not written to handle such cases, hence when a minus sign comes it assumes that stack has some value it tries to Pop elements and then gets empty stack exception

ab- , when - comes it assumes a nd b are on stack