In the following code snippet, scanner is throwing InputMismatchException after I input the value for coach and press enter. However if I use coach=sc.next(); , no such exception is thrown.
void accept() {
System.out.println("Enter name , mobile number and coach for the customer and also the amount of ticket.");
name=sc.nextLine();
mobno= sc.nextLong();
coach=sc.nextLine();
amt=sc.nextInt();
}
I expected no exception in both the cases however I cannot understand why the exception is thrown only for sc.nextLine();.
Thanks everyone!