Reverse string method

后端 未结 6 1621
暗喜
暗喜 2021-01-20 00:25

I am trying to solve the following problem but how do write the method that accepts String as an argument?

Write a method named printReverse

6条回答
  •  失恋的感觉
    2021-01-20 01:01

    try this:

    private static String reverseString(String str)
    {
        String revString = "";
    
        for(int i=str.length()-1;i>=0;i--)
        {
            revString = revString + str.charAt(i);
        }
        return revString;
    }
    

提交回复
热议问题