Easy way to reverse String

后端 未结 12 2499
北荒
北荒 2021-02-13 03:47

Without going through the char sequence is there any way to reverse String in Java

12条回答
  •  终归单人心
    2021-02-13 04:34

    public class RevString {
      public static void main(String[] args) {
        String s="jagan";
        String rev="";
        for (int i=s.length()-1;i>=0;i--) {
          rev=rev+s.charAt(i);
        }
         System.out.println("Reverse String is: "+rev);
      }
    }
    

提交回复
热议问题