题解 | #字符串反转#
字符串反转
http://www.nowcoder.com/practice/e45e078701ab4e4cb49393ae30f1bb04
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
String a = in.next();
System.out.println(getString1(a));
}
public static String getString(String a){
char[] chars = a.toCharArray();
for(int i = 0;i<chars.length/2;i++){
char tmp = chars[i];
chars[i] = chars[chars.length-1-i];
chars[chars.length-1-i] = tmp;
}
return new String(chars);
}
public static String getString1(String a){
return new StringBuilder(a).reverse().toString();
}
}
public class Main {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
String a = in.next();
System.out.println(getString1(a));
}
public static String getString(String a){
char[] chars = a.toCharArray();
for(int i = 0;i<chars.length/2;i++){
char tmp = chars[i];
chars[i] = chars[chars.length-1-i];
chars[chars.length-1-i] = tmp;
}
return new String(chars);
}
public static String getString1(String a){
return new StringBuilder(a).reverse().toString();
}
}