我是靠谱客的博主 高挑可乐,这篇文章主要介绍面试题:你能不用遍历依次打印一个数组吗?,现在分享给大家,希望可以做个参考。

不用遍历?那不就是递归嘛,简单!

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]);
    }
}



在这里插入图片描述

最后

以上就是高挑可乐最近收集整理的关于面试题:你能不用遍历依次打印一个数组吗?的全部内容,更多相关面试题:你能不用遍历依次打印一个数组吗内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(151)

评论列表共有 0 条评论

立即
投稿
返回
顶部