Home » Strings(We Suck Every1) » Reverse String

Reverse String

import java.util.*;
class ReverseString
 public static void main(String args[])
 String original, reverse ="";
 Scanner in = new Scanner(System.in);

 System.out.println("Enter a string to reverse");
 original = in.nextLine();

 int length = original.length();
 System.out.println("Length of string is "+length);

for ( int i = length - 1 ; i >= 0 ; i-- )
 reverse = reverse + original.charAt(i); // char presesnts at particular location adds up..

 System.out.println("Reverse of entered string is "+reverse);



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: