我需要帮助弄清楚如何让用户输入不超过 10 个整数,然后将它们添加到数组中并从数组中打印出来。我下面的代码在运行时向用户询问整数,然后永远运行并且不起作用。我究竟做错了什么?
public static void main(String[] args) {
Scanner input = new Scanner(System.in); // create a new scanner
System.out.print("Enter integers between 1 and 100\n ");
int[] nextNumber = new int[10];
int i = 0;
int number = input.nextInt();
while (i < nextNumber.length){
i++;
nextNumber[i] = number;
number = input.nextInt();
}
int a = 0;
while (a < nextNumber.length){
a++;
System.out.println(nextNumber[a]);
}