I'm investigating why scan.nextInt() consumes the previous integer from the second iteration onwards. Can anyone make sense of what's going on and also explain what "The scanner does not advance past any input" means exactly?
Please ignore the infinite loop. It's only for testing purposes.
Example:
Enter new data: 0
0
data entered
Enter data again: 1
executed
Enter new data: 1 <- this value is automatically entered (taken from previous input)
data entered
Enter data again:
while(true)
{
System.out.print("Enter new data: ");
System.out.println(scan.nextInt());
//scan.nextLine(); //must include but I'm not sure why
System.out.println("data entered");
System.out.print("Enter data again: ");
if(scan.hasNextInt())
{
System.out.println("executed");
//scan.nextLine(); //must include this too but not sure why
}
}