所以我正在尝试创建一个程序,用户输入其学生的年龄,直到它进入-1.在-1之后,程序必须计算学生人数和平均年龄.出于某种原因,我无法摆脱do-while循环.太头疼了!无论如何,这是代码
提前致谢.
public static void main(String[] args) {
// Input
Scanner input = new Scanner(System.in);
// Variables
int escapeNumber = 0;
int[] studentsAge = new int[50];
do {
// Input
System.out.println("Student's age (Type -1 to end): ");
// Set escapeNumber to what the user entered to break the while loop
escapeNumber = input.nextInt();
// Populate the array with the ages (Cannot be a negative number)
if (escapeNumber > 0) {
for (int arrayPos = 0; arrayPos < studentsAge.length; arrayPos++) { …Run Code Online (Sandbox Code Playgroud)