Дважды срабатывает вывод в консоль в цикле (Java)
При запуске цикла выводит сразу дважды строку "Введите через запятую Фамилию и Имя и нажмите Enter: ". Где что пропустил?
int Weight=0;
int Count=0;
System.out.println("Введите бла-бла-бла и нажмите Enter: ");
Scanner scan = new Scanner(System.in);
Weight = scan.nextInt();
System.out.println("Введите бла-бла-бла Enter: ");
Count = scan.nextInt();
ArrayList<String> arrayList = new ArrayList<>();
System.out.println("Вводим параметры");
for (int i=1; i<=Count;i++){
System.out.println("Введите через запятую Фамилию и Имя и нажмите Enter");
arrayList.add(scan.nextLine());
}
Ответы (1 шт):
Автор решения: Дмитрий
→ Ссылка
Изменил предпоследнюю строчку. Все заработало. Спасибо за подсказки.
int Weight=0;
int Count=0;
System.out.println("Введите бла-бла-бла и нажмите Enter: ");
Scanner scan = new Scanner(System.in);
Weight = scan.nextInt();
System.out.println("Введите бла-бла-бла Enter: ");
Count = scan.nextInt();
ArrayList<String> arrayList = new ArrayList<>();
System.out.println("Вводим параметры");
for (int i=1; i<=Count;i++){
System.out.println("Введите через запятую Фамилию и Имя и нажмите Enter");
arrayList.add(scan.next());
}