Well, actually my confusion lies in the following piece of code:
import java.util.Scanner;
class A
{
public static void main(
String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the first number: ");
int a=sc.nextInt();
System.out.println("Enter the second number: ");
int b=sc.nextInt();
System.out.println(a);
System.out.println(b);
}
}
When the first message "Enter the first number" is displayed, and then if I input both the values for a and b at once, on the same line
and then press ENTER, both are read. But after second message "
Enter the second number" is dispalyed, it does not take anymore input and directly prints the values of a and b, although there is a call to the next() function after the second message.
This is what I can't get, why is the next() function not called a second time?