Function with parameters Learn programming Java

Lesson:

Functions


Exercise:

Function with parameters


Objetive:

Create a program whose Main must be like this:

public static void Main()
{
SayHello("John");
SayGoodbye();
}

SayHello and SayGoodbye are functions that you must define and that will be called from inside Main. As you can see in the example. SayHello must accept an string as a parameter.


Code:

public class Main
{
	public static void SayHello(String name)
	{
		System.out.println("Hello" + name);
	}
	public static void SayGoodBye()
	{
		System.out.println("Adios");
	}
	public static void main(String[] args)
	{
		SayHello("Jonh");
		SayGoodBye();
	}
}

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.