小编Goj*_*ira的帖子

这个do-while循环不起作用,我无法理解为什么

所以我正在尝试创建一个程序,用户输入其学生的年龄,直到它进入-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)

java do-while

3
推荐指数
1
解决办法
81
查看次数

标签 统计

do-while ×1

java ×1