Reverse a string in Java

前端 未结 30 2579
礼貌的吻别
礼貌的吻别 2020-11-21 13:12

I have \"Hello World\" kept in a String variable named hi.

I need to print it, but reversed.

How can I do this? I understand there

30条回答
  •  隐瞒了意图╮
    2020-11-21 14:05

    It gets the value you typed and returns it reversed ;)

    public static  String reverse (String a){
        char[] rarray = a.toCharArray();
        String finalvalue = "";
        for (int i = 0; i < rarray.length; i++)
        {
            finalvalue += rarray[rarray.length - 1 - i];
        }   
    return finalvalue;
    

    }

提交回复
热议问题