不用遍历?那不就是递归嘛,简单!
public class test {
public static void main(String[] args) {
int[] arr = new int[]{0,1,2,3};
printArray(arr, arr.length);
}
public static void printArray(int[] arr, int n) {
if (n <= 0) return;
printArray(arr, n - 1);
System.out.println("arr[" + (n - 1) + "] = " + arr[n - 1]);
}
}

最后
以上就是高挑可乐最近收集整理的关于面试题:你能不用遍历依次打印一个数组吗?的全部内容,更多相关面试题:你能不用遍历依次打印一个数组吗内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复