008-006-010
Using Method Return Values
Medium
Problem Description
Using Method Return Values
In this problem, you will implement three methods (isEven, classify, and absolute). Each method receives an argument and returns an appropriate value.
Learning Objective: Understand how to compose processing using method return values
Overview
Methods with return values pass calculation or evaluation results back to the caller. Return values can be stored in variables or used directly as arguments to other methods.
Specifications
boolean isEven(int n): returnstrueif n is even,falseif oddString classify(int n): returns"positive","negative", or"zero"int absolute(int n): returns the absolute value of n
Input Format
n1
n2
n3
- Line 1: integer passed to
isEven - Line 2: integer passed to
classify - Line 3: integer passed to
absolute
Output Format
result of isEven(n1)
result of classify(n2)
result of absolute(n3)
Example
Input:
4
7
-8
Output:
true
positive
8
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