Kristian Kristian - 10 months ago 51
Java Question

Scanner only reads first word instead of line

In my current program one method asks the user to enter the description of a product as a

input. However, when I later attempt to print out this information, only the first word of the
shows. What could be the cause of this? My method is as follows:

void setDescription(Product aProduct) {
Scanner input = new Scanner(;
System.out.print("Describe the product: ");
String productDescription =;
aProduct.description = productDescription;

So if the user input is "Sparkling soda with orange flavor", the
will only yield "Sparkling".

Any help will be greatly appreciated!


Replace next() with nextLine():

String productDescription = input.nextLine();