Hello I am having a little bit of trouble with my code I am almost at the end yet I have a small problem, is there a way to remove the last "-" of the output of this code? for example I input "hello" the output I am for should be "15-12-12-5-8" and not "15-12-12-5-8-" I tried using str.substring(0,str.length()-1); but in the end it removed all of the dash and I only want the last dash of the code to be removed, I hope anyone can help me.
your loop says "print each character, followed by a dash"
but it seems like you don't want to do that...you only want to print a dash if there is another character left to print. So, you need some kind of condition around the printing of the dash. Can you think about a way to determine if there is another character still?
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
I have a naughty trick to get rid of the last −; I have mentioned it recently in a different context.
Find out about a StringJoiner object, which can produce exactly the output you want and does all the testing for you.