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 Greeter class
  • sayHello(String name) method returns "Hello, " + name + "!"
  • sayGoodbye(String name) method returns "Goodbye, " + name + "!"
  • In the Main class, use Scanner to read two lines; pass the first to sayHello and the second to sayGoodbye, 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