Tuesday, July 28, 2009

Reverse a String - Java Program

Hi friends, welcome back to Java Code Online. The Java Code discussed today, helps in reversing any String that is entered to the system. It displays the reverse String of the String that is entered in the system.

The Java Code is given below:-

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class ReverseString {

/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
System.out.println("Enter a string to be reversed: ");
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String str = br.readLine();
StringBuffer sb = new StringBuffer().append(str);
System.out.println("The reversed string is:\n"+sb.reverse().toString());
}

}


Keep buzzing Java Code Online for more info on Java.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.