import java.util.Scanner;
public class Unit1Err1{
public static void main( String[] args ) {
Scanner inPut = new Scanner(System.in);
String sName = inPut.nextLine();
double gpa = inPut.nextDouble();
int noOfCourses = inPut.nextInt();
System.out.printf("%11s %18s %12s","Name","GPA","No Of Courses");
System.out.println();
System.out.printf("%11s %18s %12s",sName,gpa,noOfCourses);
System.out.println();
sName = inPut.nextLine();
gpa = inPut.nextDouble();
noOfCourses = inPut.nextInt();
System.out.printf("%11s %18s %12s",sName,gpa,noOfCourses);
System.out.println();
sName = inPut.nextLine();
gpa = inPut.nextDouble();
noOfCourses = inPut.nextInt();
System.out.printf("%11s %18s %12s",sName,gpa,noOfCourses);
System.out.println();
}
}
The error which shows up is:
CompileRunTest: throwable = java.util.InputMismatchException
java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:909)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextDouble(Scanner.java:2456)
at Unit1Err1.main(Unit1Err1.java:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at tester.TesterThread.invokeMain(TesterThread.java:32)
at tester.TesterThread.run(TesterThread.java:38)
I have read that this error is most likely due to a value trying to be input into a variable type which it is not. But my input is:
Henny Penny
3.5
15
Zen Ben
2.8
10
Jerry Berry
4.0
25
And unless its a simple mistake I believe I have everything correct so far. Any help at all would be greatly appreciated,
Note:this was marked as duplicate, but I have done what the other one has shown and it still has yet to work