当我运行程序时,它没有读取字符串并将其存储在tempAddress中,而是在我输入之前直接打印下一行。对于前两个单词,使用next可以工作,但第三个单词包含多个单词,因此需要其他方法。通过我的研究,我发现nextLine()是答案,但我无法像其他人那样使其正常工作,提前感谢您的帮助。
System.out.println("Enter Employee First Name: ");
String tempFirstName = input.next();
employeesArray[i].setFirstName(tempFirstName);
System.out.println("Enter Employee Last Name: ");
String tempLastName = input.next();
employeesArray[i].setLastName(tempLastName);
System.out.println("Enter Employee Address: ");
String tempAddress = input.nextLine();
employeesArray[i].setAddress(tempAddress);
System.out.println("Enter Employee Title: ");
String tempTitle = input.next();
employeesArray[i].setTitle(tempTitle);
nextLine()
有什么期望?为什么你觉得“无法使其正常工作”? - Balwinder SinghSystem.out.println("输入员工地址:"); String tempAddress = input.nextLine(); System.out.println("tempAddress : " + tempAddress);
- Balwinder Singh