我相信我已正确编写了所有代码,但是我收到了此错误,有人可以帮助我理解以下内容:
Exception in thread "main" java.util.InputMismatchException
at java.base/java.util.Scanner.throwFor(Scanner.java:939)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextDouble(Scanner.java:2564)
at gangPackage.newClass.main(newClass.java:15)
这是我的代码:
package gangPackage;
import java.util.*;
public class newClass {
public static void main (String[] args) {
Scanner Scan = new Scanner(System.in);
String name;
int age;
double gpa;
System.out.println("Enter your name: ");
name = Scan.nextLine();
System.out.println("Enter students age: ");
age = Scan.nextInt();
System.out.println("Enter your GPA: ");
gpa = Scan.nextDouble();
System.out.printf(name + " is " + age + " years old. And has a GPA of " + gpa);
}
}
最佳答案
原文链接:https://www.f2er.com/java/532870.html