Skip to content

Exercise_20_23 #17

Open
Open

Description

@csv77

Hi,
One criterion is missing before the 68th row, at the while loop premise. Instead of

while (!operatorStack.isEmpty() && (operatorStack.peek() == '*' || operatorStack.peek() == '/' || operatorStack.peek() == '%' )) { processAnOperator(operandStack, operatorStack); }

the correct version would be:

while(!operatorStack.isEmpty() && (operatorStack.peek() == '*' || operatorStack.peek() == '/' || operatorStack.peek() == '^' || operatorStack.peek() == '%')) { processAnOperator(operandStack, operatorStack); }

Without this criterion (operatorStack.peek() == '^' ||) the following expression gives wrong result:
(5 * 2 ^ 3 * 2 + 2 * 3 % 2) * 4 is correctly 320, but without this criterion it is 1280, because 2 ^ 3 * 2 is evaluated as 2 ^ 6.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions