Challenge: Return a Custom Greeting
In this coding challenge, you’ll write a method that returns a String instead of printing directly.
Your task
Create a method named
greetthat:takes a
String nameand anint agereturns a message like:
Ali is 21 years old.
In
main:call
greet("Ali", 21)store the returned value in a
Stringvariable (example:message)print the message
Expected output
Ali is 21 years old.
Reminder:
returnsends 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
Create a method named
greetthat:takes a
String nameand anint agereturns a message like:
Ali is 21 years old.
In
main:call
greet("Ali", 21)store the returned value in a
Stringvariable (example:message)print the message
Expected output
Ali is 21 years old.
Reminder:
returnsends a value back to the caller.System.out.println(...)prints it to the screen.