使用tutorialspoint.com时出现NoSuchElementException

问题描述

因此,我正在使用以下编译器站点来编写代码:https://www.tutorialspoint.com/compile_java_online.php

当我运行代码时,出现此错误:

Exception in thread "main" java.util.NoSuchElementException
    at java.util.Scanner.throwFor(Scanner.java:862)
    at java.util.Scanner.next(Scanner.java:1485)
    at java.util.Scanner.nextInt(Scanner.java:2117)
    at java.util.Scanner.nextInt(Scanner.java:2076)
    at WorkingWithLoops.main(WorkingWithLoops.java:22)

这是我的代码:

import java.util.Scanner;

 public class WorkingWithLoops {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int negative = 0,positive = 0,sum = 0,value;
       
        System.out.print("Enter a value: ");
        value = input.nextInt();
       
        while (value != 0){
            if (value < 0){
                negative++;
            }
            else {
                positive++;
            }
           
            sum += value;
           
            System.out.print("\nEnter a value: ");
            value = input.nextInt();
           
        }
         System.out.print(
            "Positive integers: " + positive +
                "\nNegative integers: " + negative +
                "\nSum: " + sum +
                "\nAverage: " + ((sum * 1.0) /(positive/negative)) 
            );
       
           
    }
}

它会打印出输入一个值以接受该值,但不进行任何计算或执行任何操作。我不确定我的代码的哪一部分混乱了。我对Java还是有点陌生​​,我习惯于使用C ++。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)