I have this code snippet:
for(int i=0; i<3; i++){
pers[i] = new personalInfo();
System.out.printf("Please input the name for person %s: ", i );
inName = input.nextLine();
pers[i].setName(inName);
System.out.println(pers[i].getName);
System.out.printf("Please input the address for person %s: ", i );
inAddress = input.nextLine();
pers[i].setAddress(inAddress);
System.out.println(pers[i].getAddress);
System.out.printf("Please input the age for person %d: ", i );
inAge = input.nextInt();
pers[i].setAge(inAge);
// input.nextLine();
System.out.println(pers[i].getAge);
System.out.printf("Please input the phone number for person %d, without dashes included (ex. 1112223333): ", i );
inPhoneNumber = input.nextLong();
pers[i].setPhoneNumber(inPhoneNumber);
System.out.println(pers[i].getPhoneNumber);
// input.nextLine();
}
I get problems because nextInt() and nextLong() are not consuming the newlines. However, this can be solved by uncommenting only the LAST input.nextLine() (even though the loop called nextInt() and nextLong()). I don't understand why I don't need both input.nextLine() calls. It seems like there should be 2 newlines in the buffer at the end of the first iteration, but there is only one. Is this because nextInt() and nextLong() consume leading newlines up to the respective integer or long? Let me know if I'm not making sense.