声明落到下一行

Bla*_*268 0 java

出于某种原因,我的陈述不断进入下一行,而没有按照预期进行.

package Employee;
import java.util.Scanner;
import static java.lang.System.out;



public class EmployeeTest {

public static void main (String args[]) {

out.println ("Welcome to employee storer: ");

Scanner imput = new Scanner (System.in);
Employee employee1 = new Employee();// Creates an employee
Employee employee2 = new Employee();

out.println ("Please enter first name: ");
String fName = imput.nextLine(); //reads keyboard
    employee1.setfName(fName);// sets first name

out.println("please enter last name: ");
String lName = imput.nextLine();//reads keyboard
    employee1.setlName(lName);// sets second name

out.println("Please enter pay: ");
double pay = imput.nextDouble();//reads keyboard
    employee1.setPay(pay);//sets the pay

out.println ("Please enter first name: ");
String fName1 = imput.nextLine(); //reads keyboard
    employee2.setfName(fName1);// sets first name

out.println("please enter last name: ");
String lName1 = imput.nextLine();//reads keyboard
    employee2.setlName(lName1);// sets second name

out.println("Please enter pay: ");
double pay1 = imput.nextDouble();//reads keyboard
    employee2.setPay(pay1);//sets the pay

employee1.printer();// prints the info
employee2.printer();// same here

employee1.raise();
}
Run Code Online (Sandbox Code Playgroud)

}

我的问题是第二个fName输入,它从来没有从控制台获得输入,它最终看起来像这样

"Welcome to employee storer: 
 Please enter first name: 
 Jake
 please enter last name: 
 Smith
 Please enter pay: 
 100
 Please enter first name: 
 please enter last name: 
 Jake
 Please enter pay: 
 100
 The employee Jake Smith yearly salary is: 1200.0
 The employee Jake yearly salary is: 1200.0
 Your raise is: 120.0
 Your new yearly pay is: 1200.0120.0"
Run Code Online (Sandbox Code Playgroud)

我的方法类如下所示:package Employee; import static java.lang.System.out;

public class Employee {
private String fName;
private String lName;
private double pay;

public void payCheck() {
    if (pay > 0 )
        pay = 0;
}
public double yearly() {
    double overall = pay * 12; 
    return overall;
}
public void printer() {
    out.println( " The employee " + fName + " " + lName + 
            " yearly salary is: " + pay * 12 );
}
public void raise() {
    double year = pay * 12;
    double increase = .1;
    double raise = increase * year;
    out.println("Your raise is: " + raise );
    out.print("Your new yearly pay is: " + year + raise);
}


// Getters and setters 
public String getfName() {
    return fName;
}
public void setfName(String fName) {
    this.fName = fName;
}
public String getlName() {
    return lName;
}
public void setlName(String lName) {
    this.lName = lName;
}
public double getPay() {
    return pay;
}
public void setPay(double pay) {
    this.pay = pay;
}
Run Code Online (Sandbox Code Playgroud)

}

我也得到了最终年薪的奇怪输出.不确定为什么,任何帮助将不胜感激.

Ray*_*nic 5

nextDouble()将只返回Double该行的值,使行返回后面,这将由下一个nextLine()语句拾取.