Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 循环似乎工作不正常,它跳过了第一个字段_Java - Fatal编程技术网

Java 循环似乎工作不正常,它跳过了第一个字段

Java 循环似乎工作不正常,它跳过了第一个字段,java,Java,好吧,这是我的问题。这是我正在编写的代码。在第一个循环中,这很好。但当它进入下一个循环时,申请人名称上的光标不会出现。它跳转到学习水平。为什么会这样?我的代码有问题吗 while (totalScholarship != 0) { System.out.println("Applicant Name: "); s.setsName(input.nextLine()); System.out.println("Study Level: "); System.out

好吧,这是我的问题。这是我正在编写的代码。在第一个循环中,这很好。但当它进入下一个循环时,申请人名称上的光标不会出现。它跳转到学习水平。为什么会这样?我的代码有问题吗

while (totalScholarship != 0) {
    System.out.println("Applicant Name: ");
    s.setsName(input.nextLine());

    System.out.println("Study Level: ");
    System.out.println("1-Pre Dip, 2-Dip 3-Degree");
    s.setiStudyLevel (input.nextInt());

    System.out.println("Personallity Score: ");
    s.setiPersonalityScore(input.nextInt());

    System.out.println("Parent Income: ");
    s.setdParentIncome(input.nextDouble());

    int iPersonalityScore = s.getiPersonalityScore();
    double dParentIncome = s.getdParentIncome();
    if (iPersonalityScore < 350) {
        if (dParentIncome >= 3000) {
            System.out.println("NOT ELIGIBLE!");
        } else {
            System.out.println("CONGRATULATIONS!");
            bEligible = true;
        }
    } else {
        System.out.println("CONGRATULATIONS!");
    }

    System.out.println("");
    System.out.println(s.toString());
}
while(总奖学金!=0){
System.out.println(“申请人名称:”);
s、 setsName(input.nextLine());
System.out.println(“学习级别:”);
系统输出打印LN(“1-预浸,2-浸3度”);
s、 setiStudyLevel(input.nextInt());
System.out.println(“个性分数:”);
s、 setiPersonalityScore(input.nextInt());
System.out.println(“母公司收入:”);
s、 setdParentIncome(input.nextDouble());
int iPersonalityScore=s.getiPersonalityScore();
double dParentIncome=s.getdParentIncome();
if(iPersonalityScore<350){
如果(dParentIncome>=3000){
System.out.println(“不合格!”);
}否则{
System.out.println(“恭喜你!”);
可信=真实;
}
}否则{
System.out.println(“恭喜你!”);
}
System.out.println(“”);
System.out.println(s.toString());
}
在此之后添加
input.nextLine()

System.out.println ("Parent Income: ");
s.setdParentIncome (input.nextDouble());
因为在第一次迭代中,您在
input.nextDouble()
之后按下的
“Enter”
键在第二次迭代中作为
input.nextLine()
内的输入接收。这就是为什么您觉得输入被跳过了。 例如:

int option = input.nextInt();
input.nextLine();  // Consume newline left-over
String str1 = input.nextLine();

因此,在循环结束时输入一个
input.nextLine()
,它将正常工作

请参见。基本上,在调用
nextDouble()
之后,仍然需要使用一个换行符,我猜输入是scanner的一个实例。可能会发布您的示例输入。