我收到 InputMismatchException 错误,尽管一切都应该按预期工作。只有当用户必须输入一个 int 值(setAge)时,我才会收到错误消息。为什么?
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
Withdraw myAccount = new Withdraw();
Customer Jack = new Customer();
out.println("Enter your full name");
String FullName = keyboard.next();
Jack.setName(FullName);
out.println("Enter your address");
String Address = keyboard.next();
Jack.setAddress(Address);
// I GET THE ERROR IN THE LINES BELOW.
out.println("Enter your age");
int age = keyboard.nextInt();
Jack.setAge(age);
这是 Customer 类的代码
public class Customer {
String name;
String address;
int age;
public void setName(String NameIn) {
name = NameIn;
}
public String getName() {
return name;
}
public void setAddress(String addressIn) {
address = addressIn;
}
public String getAddress() {
return address;
}
public void setAge(int ageIn) {
age = ageIn;
}
public int getAge() {
return age;
}
提前谢谢大家!