Reverse a string in Java

前端 未结 30 2456
礼貌的吻别
礼貌的吻别 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:04

    It is very simple in minimum code of lines

    public class ReverseString {
        public static void main(String[] args) {
            String s1 = "neelendra";
            for(int i=s1.length()-1;i>=0;i--)
                {
                    System.out.print(s1.charAt(i));
                }
        }
    }
    

提交回复
热议问题