Create a function called 'sayMyName'. It will take one parameter. Call this parameter 'myName'. Return the phrase "Hello, my name is " and the myName parameter.
Ex: If name is 'Dan' it should return the string:
'Hello, my name is Dan'.

Respuesta :

ijeggs

Answer:

   public static String sayMyName(String myName){

       return "Hello, my name is "+myName;

   }

Explanation:

Using Java programming language

The method (function) sayMyName () is created to accept a String variable as a parameter and return a string which has the phrase Hello, my name is concatenated with the argument passed to it

See below a complete program with a main that prompts a user for a name, calls sayMyName and passes the name entered by the user as an argument

import java.util.Scanner;

public class num3 {

   public static String sayMyName(String myName){

       return "Hello, my name is "+myName;

   }

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.println("Please enter your name");

       String name = in.nextLine();

       System.out.println(sayMyName(name));

   }

}