clear buffer in java code example

Example 1: bufferedreader java

import java.io.BufferedReader;
//
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.println(reader.readLine());

Example 2: declare bufferedreader java

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

Example 3: java clear bufffer to take next string inpuit

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

Tags:

Java Example