008-001-009
Method Definition: No Parameters
Easy
Problem Description
Method Definition: String Parameter
In this problem, you will create a program that defines methods accepting a String parameter (sayHello(String name) and sayGoodbye(String name)) in a Greeter class, and returns a constructed greeting string.
Learning Objective: Understand definition and invocation of methods that accept a string argument and return a value
Overview
Read two names from standard input, call the respective greeting methods, and print the results.
Specifications
- Create a
Greeterclass sayHello(String name)method returns"Hello, " + name + "!"sayGoodbye(String name)method returns"Goodbye, " + name + "!"- In the
Mainclass, useScannerto read two lines; pass the first tosayHelloand the second tosayGoodbye, then print the results
Input Format
<name for sayHello>
<name for sayGoodbye>
Output Format
Hello, <name1>!
Goodbye, <name2>!
Execution Example
Input:
World
Java
Output:
Hello, World!
Goodbye, Java!
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