gpt4 book ai didi

Java数组,打印数组中存储的内容

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

如何以简单的方式打印数组中存储的内容。我已经盯着这个看了三个小时了!

import java.util.Scanner;

public class December2012 {

public static void main(String[] args) {

int[] array = new int[100];
int sum = 0;
int i = 0;
Scanner input = new Scanner(System.in);
while (sum <= 100 && i < array.length) {
System.out.print("Write in the " + (i + 1) + "th number: ");
array[i] = input.nextInt();
sum += array[i];
i++;

}
System.out.print("You added: ");
System.out.print(array[i] + " ");

System.out.println("\nsum is " + sum);
}
}

最佳答案

最简单的方法是

System.out.println(Arrays.toString(array));

关于Java数组,打印数组中存储的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19480782/

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