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 typeString?
and default valuenull
The
surname
of typeString?
and default valuenull
The
age
of typeInt?
and default valuenull
Note: Parameter types should include
?
, so the above should beString?
andInt?
instead ofString
andInt
. This is because we want to allow passingnull
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 1400+ tech skills courses.