Say, a name is given-- last name only. The max allowed is 20 characters long. Is there a way to take the given name and add on spaces (" ") to the end of it to make it 20 characters long?
Printable View
Say, a name is given-- last name only. The max allowed is 20 characters long. Is there a way to take the given name and add on spaces (" ") to the end of it to make it 20 characters long?
Yes.
Look for useful methods in the String API docs.
One method is suggested by the title you chose for the thread. (think for loops and string concatenation: foo+" "). Another (better but more sophisticated) comes from the fact that you are actually formatting the string to have a specific length.
Try this:
Code:while(name.length() < 20)
name += " ";