Click here for important information about

Center String method creation

May 11, 2011 at 04:30:31
Specs: Windows 7
Write a method 'center' that takes a string (guaranteed to contain an even number of characters) and a field width (guaranteed to be even) and returns a centered version of the string within the given field width (with extra spaces added on to make up the difference). Note that you can find the number of characters in a string with "st.length()" and add on new characters with "st += '?';", where '?' is the character you want to add on.

public String center (String st, int width) {
return "";

See More: Center String method creation

May 11, 2011 at 05:56:21
It depends on the allowable width of the fill character. Also is the filled string required to equal the field width. With a mono spaced font they will be times when it would look terrible. Also is the space between words equal character width plus 2 fill spaces. That is why word processors have microjustification and use proportional fonts.

Report •
Related Solutions

Ask Question