137k views
2 votes
Given a string name, e.g. "Bob", return a greeting of the form "Hello Bob!". helloName("Bob") → "Hello Bob!" helloName("Alice") → "Hello Alice!" helloName("X") → "Hello X

User Jordana
by
3.6k points

1 Answer

5 votes

Answer:

public class num1 {

public static String helloName(String name){

return "Hello "+name+"!";

}

public static void main(String[] args) {

System.out.println(helloName("Alice"));

}

}

Step-by-step explanation:

Java programming language has been used for this task.

Start by defining a method that returns a String the method's name is helloName(name); Which receives a String parameter

In the method's body return the String name which is passed as an argument with the the word "Hello" concatenated.

Call The method in the main method passing any name as an argument

User Hretic
by
4.4k points