Skip to content

Instantly share code, notes, and snippets.

@javamultiplex
Created September 20, 2017 10:35
Show Gist options
  • Save javamultiplex/29a5ab0f1421012927959a7954f9934b to your computer and use it in GitHub Desktop.
Save javamultiplex/29a5ab0f1421012927959a7954f9934b to your computer and use it in GitHub Desktop.
Reverse of String using reverse() function
package com.javamultiplex.string;
import java.util.Scanner;
/**
*
* @author Rohit Agarwal
* @Category String Questions
* @Problem Reverse of String Using reverse() function
*
*/
public class ReverseStringUsingInBuiltFunction {
// Here we are using reverse() function of StringBuffer class.
public static void main(String[] args) {
Scanner input = null;
try {
input = new Scanner(System.in);
System.out.println("Enter String: ");
String string = input.nextLine();
// Converting String to StringBuffer
StringBuffer newString = new StringBuffer(string);
newString = newString.reverse();
System.out.println("Reversed String:\n" + newString);
} finally {
if (input != null) {
input.close();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment