小小新知识
import java.util.Scanner; public class StrTest { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.next(); char[] chars = str.toCharArray(); //将字符串转换为字符数组 for (int i = (str.length()) - 1; i >= 0; i--){ // 根据字符串长度判断i的范围 System.out.print(chars[i]); //逆向打印字符数组 } } }