我一直在编写一个 Java 应用程序,它接受 6 个值(第一部分为 2,第二部分为 3,最后部分为 1)。然后它输出第一个数据集的平均值,然后是第二个,然后是总平均值。
import java.io.*;
import static java.lang.System.*;
import java.util.Scanner;
class Main{
public static void main (String str[]) throws IOException {
Scanner scan = new Scanner(System.in);
System.out.println("Please enter your test grades.");
double t1 = scan.nextInt();
double t2 = scan.nextInt();
System.out.println("Please enter your quiz grades.");
double q1 = scan.nextInt();
double q2 = scan.nextInt();
double q3 = scan.nextInt();
System.out.println("Please enter your homework average.");
double hmw = scan.nextInt();
double arc1 = ((t1 + t2) / 2);
System.out.println("Test Average:" + arc1);
double arc2 = ((q1 + q2 + q3) / 3);
System.out.println("Quiz Average:" + arc2);
double arcfinal = ((arc1 * 0.5) + (arc2 * 0.3) + (hmw * 0.2));
System.out.println("Final Grade:" + arcfinal);
}
}
我无法弄清楚我的编码有什么问题。这是我的错误:
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:907)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextInt(Scanner.java:2160)
at java.util.Scanner.nextInt(Scanner.java:2119)
at average.main(Main.java:13)