java 面试题整理三

来源:互联网 发布:为什么淘宝客服打不开 编辑:程序博客网 时间:2024/05/20 03:06

题一:使用递归方式实现颠倒字符串

public static void reverse(char[] str,int startIndex, int endIndex) {        char s = str[startIndex];        str[startIndex] = str[endIndex];        str[endIndex] = s;        if((++startIndex)<=(--endIndex)) {            reverse(str,startIndex,endIndex);        }else {            System.out.println(new String(str));        }    }
原创粉丝点击