003-001-014
Basic Arithmetic Operators
Easy
Problem Description
Basic Arithmetic Operators
In this problem, you will create a program that reads two integers a and b from standard input, then computes and displays the results of five arithmetic operators—addition, subtraction, multiplication, division, and modulus—to standard output.
Learning Objective: Understand Java's basic arithmetic operators (addition, subtraction, multiplication, division, modulus)
Overview
Java supports five arithmetic operators: +, -, *, /, %. Note that integer division truncates the decimal part.
Input Format
a
b
- Line 1: int value a (b ≠ 0)
- Line 2: int value b (b ≠ 0)
Specifications
- Read two integers a and b using Scanner
- Display the result of addition, subtraction, multiplication, division, and modulus
Output Format
a + b = [addition result]
a - b = [subtraction result]
a * b = [multiplication result]
a / b = [division result]
a % b = [modulus result]
Sample I/O
Input:
17
5
Output:
17 + 5 = 22
17 - 5 = 12
17 * 5 = 85
17 / 5 = 3
17 % 5 = 2
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