用递归机制逆序输出一个字符串

Posted 左边啊

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用递归机制逆序输出一个字符串相关的知识,希望对你有一定的参考价值。

 1 package fa.ct;
 2 
 3 public class Nixu {
 4 
 5     static String input="abcdefg";
 6     public static  String ltof(String input){
 7         if(input.isEmpty()){
 8             return input;
 9         }
10         return ltof (input.substring (1)) + input.charAt (0);
11     }
12     public static void main(String[] args) {
13         System.out.println(input);
14         System.out.println(ltof(input));
15     }
16 
17 }

 

以上是关于用递归机制逆序输出一个字符串的主要内容,如果未能解决你的问题,请参考以下文章