Re: Skipping Input Problem
Hello Matty Alan,
Welcome to the Java Programming Forums.
I tested this and can see that it does indeed skip the last Name = Input.nextLine();
Upon further testing and reading about the Scanner class, the issue seems to be down to nextLine(); method.
Scanner (Java Platform SE 6)
Quote:
Originally Posted by Oracle
Advances this scanner past the current line and returns the input that was skipped. This method returns the rest of the current line, excluding any line separator at the end. The position is set to the beginning of the next line.
Since this method continues to search through the input looking for a line separator, it may buffer all of the input searching for the line to skip if no line separators are present.
If you update to:
Code Java:
System.out.print("Product Code: ");
Code = Input.next();
System.out.println("Product Discription: ");
Discription = Input.next();
System.out.println("Price: $");
Price = Input.nextDouble();
System.out.println("Quantitiy: ");
Quantity = Input.nextShort();
System.out.println("Sales Rep: ");
Name = Input.next();
Then it works fine.
But it doesn't solve the issue for the "Discription" variable.
I'm sure the description will contain more than one word and Input.next(); will throw a java.util.InputMismatchException if we try this.