You only “flush” the output in Java.
I suspect you mean, when to discard the rest of the line. To do this you can call
input.nextLine();
You need to do this after nextInt() as you expect to be reading from the next line.
solved how and where to use standard input flush in java? [closed]