0

So I want to add certain amount of tasks to an array list based on the user input but the problem is that the loop wont stop to ask the user of each task but will stop only on the last one can someone tell me why is it skipping all but the last task?

System.out.println("How many tasks would you like to add?");

int userInput = input.nextInt();

if (userInput>0) {
    for (int i =1;i<=userInput;i++){
        System.out.println("task #"+i);
        String task =input.nextLine();
        listOfTasks.add(task);
    }
}

This is the output of the program

Konrad Rudolph
  • 482,603
  • 120
  • 884
  • 1,141

0 Answers0