0

I want to input several employee details using a for-loop. However, the program is not letting me input each detail sequentially. Here is the code:

Scanner input = new Scanner(System.in);

    String name, dept;
    double salary;

    for(int i=0; i<3; i++) {

        System.out.println("Input name of employee "+ i);
        name = input.nextLine();

        System.out.println("Input department of employee "+ i);
        dept = input.nextLine();    

        System.out.println("Input salary of employee "+ i);
        salary = input.nextDouble();
    }

    input.close();
}

Here is what is happening after first iteration:

enter image description here

The program is not letting me input name first, then salary of second employee. How to fix this?

TechXpert
  • 55
  • 1
  • 6

0 Answers0