我正在运行此代码段:
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);
}
我得到了这个输出:
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:
你可以看到,在循环的第一次迭代中,它会提示输入名称,等待输入,然后提示输入地址。但是,在循环的第二次迭代中,它会在同一行上提示输入名称和地址,然后等待输入。这对我来说没有意义。有人可以帮我解释一下吗?