I would use a string tokenizer to count the number of names you have. Then you can easily manipulate each token and then append them altogether for your return value. I can't really help you beyond that without knowing what language you are using.
Basically user has to input their name like jOhn JhOnson
and i have to return it as John Jhonson
but if the user has 3 names like jonny jon jony
I have to return it like Jonny-Jon Jony
and i have no idea how
Can't figure out how to return input