以前试图弄清楚这一点并且无法弄清楚,它只是打印数组中的最后一个数字。
import java.util.Scanner;
public class proj81 {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
int[] arry = new int[11];
System.out.print("You will be asked to enter a set of 10 integers.\n");
int i = 1;
int count = 0;
while(count<=9) {
System.out.print("Please enter an integer: ");
arry[i] = reader.nextInt();
count++;
}
System.out.print(arry[i]);
}
}
答案 0 :(得分:3)
当然可以,print语句不在while循环中。试试这个:
while(count <= 9) {
System.out.print("Please enter an integer: ");
arry[count] = reader.nextInt();
count++;
System.out.print(arry[count]);
}
我已将i
替换为count
,因为i
只是一个常量,所以您不需要填充数组。
答案 1 :(得分:0)
您有两个问题: