您的位置:首页 > 其它

运用递归实现字符串反转

2008-07-28 16:03 295 查看
//-------------------------------------------------
//程序目的:运用递归实现字符串反转
//-------------------------------------------------

import java.util.*;

public class Reverse
{
public static String stringA = new String(); //声明字符串变量
public static int length; //字符串长度变量

public static void main(String []args)
{
System.out.print("please input string : ");

Scanner s = new Scanner(System.in); //声明接收用户输入信息的类的对象
stringA = s.nextLine();  //接收一行信息

length = stringA.length(); //取得字符串的长度
System.out.print("the reverse string : ");
reverse(0);  //调用递归函数
System.out.println("");
}
//---------------------------------------------------------
//递归字符串反转
//---------------------------------------------------------
public static void reverse(int n)
{
if(n
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: