top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How do you reverse a string without using reverse keyword in Java?

+2 votes
183 views
How do you reverse a string without using reverse keyword in Java?
posted Jul 10, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes

Define a method for reversing a string:

int i, c=0, res; 

static void StringReverse(String s)
{
     char ch[]=new char[s.length()];

     for(i=0;i < s.length();i++)
            ch[i]=s.charAt(i);

     // Now print in reverse from length-1 to 0
     for(i=s.length()-1;i>=0;i--)
            System.out.print(ch[i]);
}
answer Feb 12, 2016 by Shivam Kumar Pandey
...