Printing reverse of any String without using any predefined function?

后端 未结 30 1327
生来不讨喜
生来不讨喜 2020-11-30 03:08

How to print the reverse of the String java is object orientated language without using any predefined function like reverse()?

30条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 03:25

    Well, printing itself would suggest a predefined function...

    Presumably, though, you could obtain the characters and concatenate them manually in reverse (i.e. loop over it backwards). Of course, you could say concatenation is a predefined function... so maybe the char array itself. But again... why?

    Is the source allowed to contain "egaugnal detatneiro tcejbo si avaj" ;-p

    Also - note that string reversal is actually pretty complex if you consider unicode combining characters, surrogate pairs, etc. You should note the caveat that most string reversal mechanisms will only deal with the more common cases, but may struggle with i18n.

提交回复
热议问题