Skip to content

Instantly share code, notes, and snippets.

@javamultiplex
Created September 20, 2017 10:40
Show Gist options
  • Save javamultiplex/b4a3f649c7f7a26eb27c646b4ec97fde to your computer and use it in GitHub Desktop.
Save javamultiplex/b4a3f649c7f7a26eb27c646b4ec97fde to your computer and use it in GitHub Desktop.
Reverse of String using Iteration
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