Challenge: Return a Custom Greeting

In this coding challenge, you’ll write a method that returns a String instead of printing directly.

Your task

  1. Create a method named greet that:

    1. takes a String name and an int age

    2. returns a message like:
      Ali is 21 years old.

  2. In main:

    1. call greet("Ali", 21)

    2. store the returned value in a String variable (example: message)

    3. print the message

Expected output

Ali is 21 years old.

Reminder:

  • return sends a value back to the caller.

  • System.out.println(...) prints it to the screen.

Challenge: Return a Custom Greeting

In this coding challenge, you’ll write a method that returns a String instead of printing directly.

Your task

  1. Create a method named greet that:

    1. takes a String name and an int age

    2. returns a message like:
      Ali is 21 years old.

  2. In main:

    1. call greet("Ali", 21)

    2. store the returned value in a String variable (example: message)

    3. print the message

Expected output

Ali is 21 years old.

Reminder:

  • return sends a value back to the caller.

  • System.out.println(...) prints it to the screen.

Java
public class Main {
public static void main(String[] args) {
// Write your code here:
}
}