[HJ12] 字符串反转

时间:2025-04-04 10:12:55
/** * @auther: 巨未 * @DATE: 2021/8/30 0030 15:41 * @Description: */ import java.util.Scanner; public class Main{ public static String rev(String str, int start, int end ){ char[] chars = str.toCharArray(); while (start < end) { char tmp = chars[start]; chars[start] = chars[end]; chars[end] = tmp; start++; end--; } return String.copyValueOf(chars); } public static void main(String[] args) { Scanner s = new Scanner(System.in); String str = s.nextLine(); System.out.println(rev(str,0,str.length()-1)); } }