Solution: Return a Custom Greeting

  • public class Main – defines the class Main.

  • public static String greet(String name, int age) – a method that takes a name (String) and age (int), then returns a greeting message.

  • return name + " is " + age + " years old."; – combines text and variables into one string and returns it.

  • public static void main(String[] args) – main method where the program begins.

  • String message = greet("Ali", 21); – calls the greet method with "Ali" and 21, storing the returned message.

Solution: Return a Custom Greeting

  • public class Main – defines the class Main.

  • public static String greet(String name, int age) – a method that takes a name (String) and age (int), then returns a greeting message.

  • return name + " is " + age + " years old."; – combines text and variables into one string and returns it.

  • public static void main(String[] args) – main method where the program begins.

  • String message = greet("Ali", 21); – calls the greet method with "Ali" and 21, storing the returned message.