gpt4 book ai didi

java - nextLine() 的问题;

转载 作者:搜寻专家 更新时间:2023-10-30 21:14:47 27 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Scanner issue when using nextLine after nextInt

我正在尝试创建一个程序,让用户使用扫描仪将值输入到数组中。

但是,当程序询问学生的近亲时,它不会让用户输入任何内容并立即结束程序。

下面是我完成的代码:

if(index!=-1)
{
Function.print("Enter full name: ");
stdName = input.nextLine();

Function.print("Enter student no.: ");
stdNo = input.nextLine();

Function.print("Enter age: ");
stdAge = input.nextInt();

Function.print("Enter next of kin: ");
stdKin = input.nextLine();

Student newStd = new Student(stdName, stdNo, stdAge, stdKin);
stdDetails[index] = newStd;
}

我试过使用 next();但它只会接受用户输入的第一个词,这不是我想要的。有没有办法解决这个问题?

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com