递归反序输出字符串
代码:
import java.util.Scanner;
public class fortyeight {
public static void main(String[] args) {
Scanner reader=new Scanner(System.in);
String s=reader.next();
gg(0,s);
}
public static void gg(int n,String s) {
if(n<s.length()) {
gg(n+1,s);
System.out.printf("%s",s.charAt(n));
}
}
}
运行结果:
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/75bc7a7fefbe67d335fc90ba688218af.png)