gulzaar

Reverse String

Feb 18th, 2015
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. /**
  2.  *
  3.  */
  4.  
  5. /**
  6.  * @author Ravinesh
  7.  *
  8.  */
  9. import java.util.*;
  10.  
  11. public class que2_str_reverse {
  12.  
  13.     /**
  14.      * @param args
  15.      */
  16.     public static String revert (String s1) {
  17.        
  18.         String rev = "";
  19.        
  20.          for (int i = s1.length() - 1 ; i >= 0; i--){
  21.             rev += s1.charAt(i);
  22.          }
  23.         return rev ;
  24.     }
  25.    
  26.    
  27.     public static void main(String[] args) {
  28.         // TODO Auto-generated method stub
  29.         Scanner scan = new Scanner(System.in);
  30.         System.out.println("Enter the string to reverse...");
  31.         String reversed = revert(scan.nextLine());
  32.         System.out.println(reversed);
  33.         scan.close();
  34.     }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment