Create a method named greeting, which accepts a string (String) and an integer (int), and displays the following phrase on the screen:
Hello. My name is <name>. I am <age>.
The method must be public and static, with a void return type.Method main is not involved in testing.
Requirements:
Solution class must have a public static greeting(String, int) method, which does not return anything.
greeting(String, int) method must output text according to task conditions.
Code:
public class Solution {
public static void greeting(String name, int age){
System.out.println("Hello. My name is "+name+". I am "+age+".");
}
public static void main(String[] args) {
String name = "JAVA;
int age = 24;
greeting(name, age);
}
}
Output:
Hello. My name is JAVA. I am 24.