You are here: Home / Topics / Create a method named greeting, which accepts a string (String) and an integer (int), and display custom output

Create a method named greeting, which accepts a string (String) and an integer (int), and display custom output

Filed under: Java on 2024-02-27 13:54:46

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.

About Author:
J
Java     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.