Quick win: join a full name
Write Apex · Beginner · 5 min · Runs in your Salesforce Developer org · Free
Scenario. A list shows each Contact's full name on one line.
Put a first and last name together with one space between them.
What you will learn
When you join two variables you must add the glue yourself. city + country gives AustinUSA. The separator is text too — ', ' here.
String cityCountry(String city, String country) {
return city + ', ' + country;
}
The task
Write a method fullName(String first, String last) that returns the two names with one space between them.
Examples:
fullName('Ada', 'Lovelace')→Ada LovelacefullName('Grace', 'Hopper')→Grace Hopper
Requirements:
- Join
first, a space andlastwith+. - Exactly one space, and nothing at the start or end.
- Keep the method's name and its two String inputs.
Starter code
String fullName(String first, String last) {
return null;
}
System.debug(fullName('Ada', 'Lovelace'));
System.debug(fullName('Grace', 'Hopper'));
When it passes
`fullName` returns `<first> <last>` for every pair of names the grader tries.
You write the Apex yourself. ApexSensei runs it and tells you what passed and what did not.