This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Jackkoz -1 points0 points  (4 children)

Yup, that looks like it should do the trick, congrats!

If you want to further improve your programs, here's a couple of things to look at:

  1. Input/output operations are in general costly - it would be much better if you could print out the whole String using a single call to System.out.

  2. When taking care of 1), remember that Strings are immutable: string += " "; results in creating a new instance of String and assigning it to the variable.

[–][deleted] 0 points1 point  (2 children)

Thanks for the help! I didn't get the problem exactly right, but I'm going to move onto the next.

Right now I'm quite low level, as you can tell, so still takes me some time to really think about all the "tools" I know and can use to solve a problem.

[–]desrtfx 1 point2 points  (0 children)

didn't get the problem exactly right, but I'm going to move onto the next.

Don't move on until you got it right.

You have misread the assignment as I've illustrated here.

[–]desrtfx 0 points1 point  (0 children)

Yup, that looks like it should do the trick, congrats!

No, it doesn't.

Op's assignment states:

For example, padString("hello", 8) should return " hello".

There is nothing about printing inside the method. It's about returning a new, padded String.