You are viewing a single comment's thread. Return to all comments →
Couple comments for this code. First and foremost, the problem was to test your knowledge of printf.
Otherwise looking just at your solution, instead of starting at j=0, you could start at s1.length() which would save you from the unnecessary loops where "if(s1.length() < 15)" is false. In fact, with the correcty initialized for loop, you could skip the if statement entirely.
Also, I wouldn't recommend building up your string in this way (printf aside) as the String is immutable and you're simply wasting memory. Java cannot optimize these appends as they occur on separate lines. You want StringBuilder here instead: http://stackoverflow.com/a/7817989/819373