输入:abcd
输出:dcba
public static void main(String[] args) { Scanner sc = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (sc.hasNext()) { // 注意 while 处理多个 case String str = sc.next(); String str1 = ""; for(int i=str.length()-1; i>=0; i--){ str1 += str.charAt(i); } System.out.println(str1); } }