Created
September 20, 2017 10:35
-
-
Save javamultiplex/29a5ab0f1421012927959a7954f9934b to your computer and use it in GitHub Desktop.
Reverse of String using reverse() function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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