gpt4 book ai didi

java - 多次打印数组中每 10 个元素以及 100 个元素

转载 作者:行者123 更新时间:2023-12-01 17:48:59 25 4
gpt4 key购买 nike

我刚刚创建了一个有 100 个元素的数组,所以现在我想先打印 10 个元素,然后继续打印 10 个元素,第三个继续打印 10 个元素。我的代码如下:

    int[] array = { 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,..., 100 };
int count = 0;
for (int i = 0; i < array.length; i++) {
count++;
if (count == 10) {
System.out.println(array[i]);
count = 0;
}
}

最佳答案

您的逻辑是正确的,唯一的问题是数组值的打印。

int[] array = { 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,....,100};
int count = 0;
for (int i = 0; i < array.length; i++) {
count++;
System.out.print(array[i]+" ");
if (count == 10) {
System.out.println();
count = 0;
}
}

关于java - 多次打印数组中每 10 个元素以及 100 个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52491940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com