0

i am using ArrayList for class, and i am unsure of why my output is incorrect when searching for the string. it is suppose to ask the user how many courses they want to input, then they would start typing away the courses (ex. TAM1, TAM2). in the console, it shows:

Enter the amount of courses intended for the list: 
3
Enter the Course ID for the list: 
Enter Course:
Enter Course:
tam1
Enter Course:
tam2
Enter Course:
tam3

why is it showing Enter Course twice, in the beginning? i am also using

for (String element : toDoList)
        System.out.println(element);

to print out the list, and it has a blank line. such as:

The list contains:

tam1
tam2
tam3

Here is my code for the while loop below:

ArrayList<String> toDoList = new ArrayList<String>(); //
    Scanner keyboard = new Scanner(System.in);
    System.out.println("Enter the amount of courses intended for the list: ");
    int initial = keyboard.nextInt();
    System.out.println("Enter the Course ID for the list: ");
    while(initial>=0) 
    {
        System.out.println("Enter Course:");
        String entry = keyboard.nextLine( );
        toDoList.add(entry);  //
        initial--;

    }

not sure what i am doing wrong...

tamngoman
  • 21
  • 5

0 Answers0