Question #288859

Store employee data that obtains from user and the input process stops when the user says no longer wants to enter any data


Expert's answer

import java.util.LinkedList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        LinkedList<String> employeeData = new LinkedList<>();
        System.out.println("Enter employee data (empty line to exit): ");
        while (true) {
            String data = in.nextLine();
            if (data.length() == 0) {
                break;
            }
            employeeData.add(data);
        }
    }
}
LATEST TUTORIALS
APPROVED BY CLIENTS