题解 | #字符串反转# 堆栈
字符串反转
http://www.nowcoder.com/practice/e45e078701ab4e4cb49393ae30f1bb04
import java.util.*;
public class Main{
public static void main(String[] abc){
Scanner s = new Scanner(System.in);
String str = s.nextLine();
Stack<Character> stack = new Stack<>();
for(char item: str.toCharArray()){
stack.push(item);
}
String ans = "";
while(!stack.empty()){
ans+=stack.pop();
}
System.out.println(ans);
}
}
public class Main{
public static void main(String[] abc){
Scanner s = new Scanner(System.in);
String str = s.nextLine();
Stack<Character> stack = new Stack<>();
for(char item: str.toCharArray()){
stack.push(item);
}
String ans = "";
while(!stack.empty()){
ans+=stack.pop();
}
System.out.println(ans);
}
}