Menu

Friday, 5 February 2016

Java Program to reverse a string

import java.util.*;
 
class RevString
{
   public static void main(String args[])
   {
      String orig, rev = "";
      Scanner in = new Scanner(System.in);
 
      System.out.println("Enter a string you want to reverse :");
      orig = in.nextLine();
 
      int length = orig.length();
 
      for ( int i = length - 1 ; i >= 0 ; i-- )
         rev = rev + orig.charAt(i);
 
      System.out.println("Reverse of string is: "+rev);
   }
}

No comments:

Post a Comment