Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

add whitespace at end of string until string reaches maxlength

843829Feb 7 2006 — edited Feb 7 2006
I am having difficulty making a loop which takes a string which you enter in, and then appends a space at the end of the string and keeps adding a space until the string is maxlength

the name of the string is target and maxSize is set to 10 so the code would be somewhere along the lines of

<code>
while (target.length() < maxSize)
{
target.append(" ") //adds a space at the end of the string
}
return (target);} //string with spaces added to the end to fill 10 spaces
</code>

I know this code doesn't work but I just need some sort of tip to put me in the right direction... any help is appreciated
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 7 2006
Added on Feb 7 2006
8 comments
918 views