Java - how to empty scanner?
Hello everyone. I am making a bit more complex program in java and need help. I ask user to type a command and then I do a certain action depending on that command. Currenetly I test it only on one possible command - pay. Syntax of the command must be following: "pay <name (string)> <amount (int)> ". It works quite nicely: if a user types two strings instead of a string and an int, it throws exception, which is catched and it prints correct syntax to the user. But there´s one problem: If a user types e.g. "pay PlayerA seven", it prints correct syntax, but next time it takes "seven" as the first argument (command name). So when the user types "pay PlayerA 75" as the second try, it takes "seven pay PlayerA" instead. How can I make the scanner to forget everything that was typed before?