019-004-007

Safe Calculator Program

Medium

Problem Description

In this problem, you will create a program that takes two integers and an operator as input, performs arithmetic operations, and displays the result to standard output.

Input Format

The first line contains integer a.
The second line contains an operator (+, -, *, /).
The third line contains integer b.

Output Format

Output the operation result as an integer.
For errors, output the following messages:

  • Zero division: "Error: Division by zero"
  • Invalid operator: "Error: Invalid operator"

Constraints

  • -1000 ≤ a, b ≤ 1000
  • operator is one of +, -, *, / or an invalid character

Key Points

  • Catch exceptions with try-catch blocks
  • ArithmeticException occurs on zero division
  • You can throw custom exceptions with throw statement

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