Linux 拨号vps windows公众号手机端

java怎么打印数组中所有的元素

lewis 8年前 (2017-01-12) 阅读数 6 #程序编程
文章标签 Java

要打印数组中所有的元素,可以使用for循环遍历数组,并使用System.out.println()方法打印每个元素。

以下是一个示例代码:

public class Main {
    public static void main(String[] args) {
        int[] array = {1, 2, 3, 4, 5};
        
        // 使用for循环遍历数组
        for (int i = 0; i < array.length; i++) {
            // 打印数组中的元素
            System.out.println(array[i]);
        }
    }
}

输出结果:

1
2
3
4
5
版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门