0

Currently i'm having an issue in that put a white space in the Item Desc will end up crashing the code due to it being recognised as a delimiter. Is there any way to override this so that I can store sentences in the array?

These are methods that are needed in the class.
    int index;
    int endDate;
    Item item;

    System.out.println("Please enter the item name ");
    String itemName = sc.next();

    System.out.println("Please enter the item description: ");
    String itemDesc = sc.next();

    database.items.add(new Item(itemName, itemDesc));

    index = database.itemIndex(itemName);
    item = database.items.get(index);
  • 1
    You need to call `nextLine()` an extra time after calling `next()` to consume the trailing newline. – shmosel Mar 23 '17 at 22:46
  • Could you explain a little better Shmosel? I'm not sure I follow. – JacobFraMoo Mar 23 '17 at 22:50
  • After you call `next()`, the cursor is still on the same line. Calling `nextLine()` will return the remaining text on that line, which is probably an empty string. You need to call `nextLine()` to move to the next line, then call `nextLine()` again to get the second line's input. – shmosel Mar 23 '17 at 22:52

0 Answers0