As buffered reader is much faster than scanner class in case of inputting values from the user, however as observed in most of the Algorithm Competitions or in case of interviews there are often multiple integers on a single input line. Hence, it becomes easier to use Scanner Class -
Scanner in=new Scanner(System.in);
int a=in.nextInt();
int b=in.nextInt();
In case of Buffered Reader, you will have to first input a line (as there is no option of readInt) and then parse the line according to number of integers on it -
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int a,b;
String line = br.readLine();
String[] strs = line.trim().split("\\s+");
a=Integer.parseInt(strs[0]);
b=Integer.parseInt(strs[1]);
Although the input may be faster in latter case, won't the parsing take up much time to divide the obtained string into indiviual integers? Hence, in such case which one of the above is more optimal or faster?
Thank you.