1、题目描述 - 如题
2、上代码
package 剑指Offfer;
import java.io.InputStreamReader;
import java.util.Scanner;
public class 字符串反转 {
public static void main(String[] args) {
Scanner in = new Scanner(new InputStreamReader(System.in));
String str = in.next();
char[] arr = str.toCharArray();
reverse(arr, 0, arr.length - 1);
System.out.println(new String(arr));
}
static void reverse(char[] arr, int l, int r) {
for(int i = 0;i < (r - l)/2 + 1;i ++) {
char tmp = arr[l + i];
arr[l + i] = arr[r - i];
arr[r - i] = tmp;
}
}
}