008-001-010
Method Definition: With Parameter
Easy
Problem Description
Method Definition: With Parameter
In this problem, you will create a Printer class with two parameterized methods (printMessage and printNumber) that each accept an argument and return a formatted string.
Learning Objective: Understand definition and invocation of methods with parameters
Overview
Define methods that receive parameters and return formatted results as strings.
Specifications
- Create a
Printerclass printMessage(String msg)method: formats the argument as"Message: " + msgand returns itprintNumber(int num)method: formats the argument as"Number: " + numand returns it
Input Format
string (message)
integer (number)
Output Format
Message: <string>
Number: <integer>
Execution Example
Input:
Hello
42
Output:
Message: Hello
Number: 42
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