I am running this code snippet:
personalInfo[] pers = new personalInfo[3];
Scanner input = new Scanner(System.in);
String inName;
String inAddress;
int inAge;
long inPhoneNumber;
for(int i=0; i<3; i++){
pers[i] = new personalInfo();
System.out.printf("Please input the name for person %d: ", i );
inName = input.nextLine();
pers[i].setName(inName);
System.out.printf("Please input the address for person %d: ", i );
inAddress = input.nextLine();
pers[i].setAddress(inAddress);
System.out.printf("Please input the age for person %d: ", i );
inAge = input.nextInt();
pers[i].setAge(inAge);
System.out.printf("Please input the phone number for person %d, without dashes included (ex. 1112223333): ", i );
inPhoneNumber = input.nextLong();
pers[i].setPhoneNumber(inPhoneNumber);
}
I get this output:
Please input the name for person 0: name
Please input the address for person 0: address
Please input the age for person 0: 18
Please input the phone number for person 0, without dashes included (ex. 1112223333): 1289308439
Please input the name for person 1: Please input the address for person 1:
You can see that on the first iteration of the loop it prompts for name, waits for input, then prompts for address. However, on the second iteration of the loop it prompts for name and address on the same line, then waits for input. This doesn't make sense to me. Can anyone please explain this for me?