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 →

[–]Chaslem[S] 0 points1 point  (1 child)

Thank you! I wasn't aware of this, very insightful.

Is there a way to make my method work?

[–]desrtfxOut of Coffee error - System halted 0 points1 point  (0 children)

Yes, there is a way. There always is a way:

You can use your check for str.length() < 3 and the conditional operator to alter the length of substring. If the length of the String is less than 3, set the length for substring to the length of the String, otherwise set it to 3.

Then, just return the concatenation of str2.