I have heard that nextInt() reads only the integers and ignores the \n at the end. So why does the following code runs successfully?
Why there is no error after we enter value of a since \n must remain in the buffer , so use of nextInt() at b should give an error but it doesn't . Why?
import java.util.Scanner;
public class useofScanner {
public static void main(String[] args) {
Scanner scanner =new Scanner(System.in);
int a = scanner.nextInt();
int b=scanner.nextInt();
System.out.println(a+b);
}
}