java clear bufffer to take next string inpuit

Java
if(!input.hasNext() || !input.hasNextInt()) {
    input.next();
    continue;
}
int cmd = input.next();
Source

Also in Java: