Exercise: Printing Personal Information

Enhance your Kotlin proficiency by practicing string formatting and nullability concepts.

We'll cover the following

Problem statement

Implement formatPersonDisplay function. It should have the String result type and the following parameters:

  • The name of type String? and default value null

  • The surname of type String? and default value null

  • The age of type Int? and default value null

Note: Parameter types should include ?, so the above should be String? and Int? instead of String and Int. This is because we want to allow passing null as a parameter value.

The function should return a string in the following format: "{name} {surname} ({age})". If any of the parameters is null, it should be omitted from the result. If all parameters are null, it should return an empty string.

Instructions

In the given code, you are presented with the requirement to implement the formatPersonDisplay function. Your task is to complete the implementation of this function based on the specified requirements.

Note: Avoid altering the original meaning, and make sure to follow the specified parameter types and their default values.

The actual output when running the provided code should be as follows:

Get hands-on with 1200+ tech skills courses.