Printing reverse of any String without using any predefined function?

后端 未结 30 1309
生来不讨喜
生来不讨喜 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:15

    How about a simple traverse from the end of the string to the beg:

    void printRev(String str) {
     for(int i=str.length()-1;i>=0;i--)
      System.out.print(str.charAt(i));
    }
    

提交回复
热议问题