Function greeting and farewell


Saturday, November 11, 2023 Difficulty: Easy

Objective

Create a Java program that implements two methods: one to greet and another to say goodbye. Then, execute both methods from the main function (Main) of the program.

Instructions

  1. Implement a function called greet that takes a name as a parameter and displays a personalized greeting on the screen. For example, if the name is John, the program should print Hello John.
  2. Implement another function called sayGoodbye that doesn't require any parameters and displays a farewell message. For example, the program can print Goodbye!.
  3. From the main function (Main), prompt the user to enter their name.
  4. Call the greet function with the name entered by the user to display the personalized greeting.
  5. Call the sayGoodbye function to display the farewell message.
  6. Run the program and observe the output, which should include both the greeting and the farewell.

Input

No input required

Output

Hello
Good Bye!

Solution

Click here to view the exercise solution

Share it

Share it on your social media and challenge your friends to solve programming problems. Together, we can learn and grow.

Copied

The code has been successfully copied to the clipboard.

More Exercises

Continue improving your Java programming skills with our selection of practical exercises from the lesson. Click on Practice and challenge your knowledge!

1

Function greeting and farewell

Develop your Java skills by creating a program with greeting and farewell functions. Learn to execute methods effectively from the main function (Main).

Functions

Practice with exercises in Java that use functions of different types. Methods, functions with parameters or values by reference among others.

Practice exercises

Keep learning

C# Programming Course

Free programming course with practical exercises and solutions in C#. Start learning right now!

CookieOwn and third party cookies to improve our services. If you go on surfing, we will consider you accepting its use.