003-001-015
Operator Precedence
Medium
Problem Description
Operator Precedence
In this problem, you will read three integers a, b, c and create a program that evaluates arithmetic expressions with and without parentheses, demonstrating how operator precedence affects results.
Learning Objective: Understand Java operator precedence and associativity rules
Overview
When multiple operators appear in the same expression, they are evaluated according to precedence rules. Parentheses can explicitly control evaluation order.
Input
Read three integers a, b, c from standard input, one per line.
Specifications
- Display result of expression without parentheses: a + b * c
- Display result with parentheses: (a + b) * c
- Display result of compound expression: a * b + c * a
- Display result with parentheses: (a + b) * (c - 1) + b
Output Format
a + b * c = 14
(a + b) * c = 20
a * b + c * a = 14
(a + b) * (c - 1) + b = 18
(when input is a=2, b=3, c=4)
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up