萌新驾到,话不多说,直接上代码,希望您能有所收获
import java.util.Scanner; public class exercise_reversal { public static void main(String [] args){ // 找重复 找变化 找出口 // 反转字符串 Scanner input = new Scanner(System.in); System.out.println("请输入您要反转的字符串:"); String i = input.next(); int l = i.length()-1; System.out.print(reverse(i,l)); } static String reverse(String chuan,int end){ if(end==0) return ""+chuan.charAt(0); return chuan.charAt(end)+reverse(chuan,end-1); } }