题解 | #数字颠倒#
数字颠倒
http://www.nowcoder.com/practice/ae809795fca34687a48b172186e3dafe
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
while (in.hasNextInt()) { // 注意 while 处理多个 case
String str = in.next();
System.out.println(myAns(str));
}
}
private static String myAns(String num) {
char [] cs = num.toCharArray();
StringBuilder sb = new StringBuilder(cs.length);
for(int i = cs.length-1; i >= 0; i--) {
sb.append(cs[i]);
}
return sb.toString();
}
private static String myAns2(String num) {
StringBuilder sb = new StringBuilder(num.length());
for(int i = num.length()-1; i >= 0; i--) {
sb.append(num.charAt(i));
}
return sb.toString();
}
}