用递归的方法实现输入输出回文

关于回文,我是第一次听说,可能会有人说,学习java这是最基本的程序。呵呵,很抱歉!我没有接触过正规的培训,只是自学的。但是今天正好我有同学需要我帮她写回文的程序,我有幸接触到回文,接触递归的,我对递归不是第一次了,以前学习c的时候就接触过,不过以前学习得时候晕头晕脑的,不知所云,就那样混过去了,今天我又和递归见面了。我就在网上搜遍了有关这些东西,看了很过,最后还是有点吃力。

最终还是把程序写出来了,有两种方法。

第一种方法:

package com.lianxi;


public class Ashuchu
{
public static void main(String args[]) throws Exception
{
byte[] b = new byte[2];
int c = System.in.read(b);
String str=new String(b,0,c);
print('a', str.charAt(0));
}


public static void print(char start, char end)
{
System.out.print(start);
if(start<end)

print((char)(start+1), end);
System.out.print(start);
}

原文地址:https://www.cnblogs.com/bjanzhuo/p/3575890.html