FileWriter not writing all string entered at user input

In my below FileWriter below, I am writing to a file called "employee.txt." It writes to the file but originally it was only appending to the file vs going into a new line each time. I since then edited the code by adding "\n" to make it go down by a line. My issue is that despite adding or removing the "\n" from my code, it seems to only take the last input a user entered. For eg. if a user wants to enter 2 employees, it only enters the last employee name. See code below:

 static int addEmployee() throws IOException{
    int x;
    String y = null;
    Scanner emp_input = new Scanner(System.in);
    System.out.println("Enter how many employees you want to add to file:\n ");
    x = emp_input.nextInt();

    for (int i=0; i<x;i++) {
    System.out.println("Add an employee name: ");
    y= emp_input.next();
    }

    try {
    FileWriter fileWriter = new FileWriter("employee.txt", true);
    fileWriter.write("\n");
    fileWriter.write(y);
    fileWriter.close();


    } catch (IOException e) {

        e.printStackTrace();
    }

Updated to printing out to screen to test output before writing to file:

    static int addEmployee() throws IOException{
        int x;
        String y = null;
        Scanner emp_input = new Scanner(System.in);
        System.out.println("Enter how many employees you want to add to file:\n ");
        x = emp_input.nextInt();


        for (int i=0; i<x;i++) {
          System.out.println("Add an employee name: ");
          y= emp_input.next();
        }

        System.out.println(y);



        return 0;

    }
}
Answer:1

I have a class with a couple of methods that convert from one generic type to another, but I want to return the original value if both: the argument type and the return type are the same. The best ...

I have this small piece of code for a prototype. I'm trying to have it so that on mousePressed() or on mouseClicked() the colour of the line clicked on will change. I can't for the life of me ...

I have a 2D array of 5 rows and 5 columns, all filled with the value 0. How can I make my program do this: Enter any random combination of row and column like 2-5, without the [] ...

Escribí un programa en Java para imprimir 10 mil mil en un bucle for. para (int i = 0; i <1000000; i ++) {System.out.println (i); } Tomó alrededor de 7,5 segundos. Escribí una clase personalizada en Java que ...