008-001-012
Method Definition: With Return Value
Medium
Problem Description
Method Definition: With Return Value
In this problem, you will define add and multiply methods with return values in a Calculator class.
Learning Objective: Understand definition and usage of methods with return values
Specifications
- Create a
Calculatorclass add(int a, int b)method returns the sum of two integersmultiply(int a, int b)method returns the product of two integers
Input Format
Four integers, one per line:
- Line 1: first argument for add
- Line 2: second argument for add
- Line 3: first argument for multiply
- Line 4: second argument for multiply
Output Format
result of add(a1, b1)
result of multiply(a2, b2)
Example
Input:
5
3
5
3
Output:
8
15
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