package com;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
public class StringReverse {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String string = " ";
StringBuffer retBuffer = new StringBuffer("");
/*
* 方法一
*/
try {
string = br.readLine();
} catch (IOException ex) {
System.out.println(ex);
}
char[] retChar = new char[string.length()];
for (int i = string.length() - 1, j = 0; i >= 0; i--, j++) {
retChar[j] = string.charAt(i);
}
System.out.println(String.valueOf(retChar));
/*
* 方法二
*/
StringBuffer sb = new StringBuffer(string);
System.out.println(sb.reverse().toString());
System.out.println(reverse(string));
}
/*
* 堆栈的方法反转
*/
public static String reverse(String in) {
String input = in;
String output;
//执行反转
Stack theStack = new Stack();
for (int j = 0; j < input.length(); j++) {
char ch = input.charAt(j);
theStack.push(ch);
}
output = "";
while (!theStack.isEmpty()) {
char ch = theStack.pop();
output = output + ch;
}
return output;
}
}