Created
September 20, 2017 10:40
-
-
Save javamultiplex/b4a3f649c7f7a26eb27c646b4ec97fde to your computer and use it in GitHub Desktop.
Reverse of String using Iteration
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 Iteration method | |
* | |
*/ | |
public class ReverseStringByIteration { | |
public static void main(String[] args) { | |
Scanner input = null; | |
try { | |
input = new Scanner(System.in); | |
System.out.println("Enter String :"); | |
String string = input.nextLine(); | |
int length = string.length(); | |
StringBuffer newString = new StringBuffer(); | |
for (int i = length - 1; i >= 0; i--) { | |
newString.append(string.charAt(i)); | |
} | |
System.out.println("Reversed String is :\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