Answer the question
In order to leave comments, you need to log in
Need to remove an element from the list and when you type "finish" from the keyboard, the program should end?
You need to remove an element from the list, more precisely, you need to enter an index from the keyboard and the element should be deleted at this index.
And when you enter "finish" from the keyboard, the program should end
public class Main {
public static void main(String[] args) {
ArrayList<String> note = new ArrayList<String>();
int count;
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("Выберите действие:\n" +
"1. Добавить задачу\n" +
"2. Вывести список задач\n" +
"3. Удалить задачу \n" +
"0. Выход");
count = Integer.parseInt(scanner.nextLine());
if (count == 1) {
System.out.println("Введите задачу для планирования");
note.add(scanner.nextLine());
System.out.println();
}
if (count == 2){
System.out.println("Весь список задач для планирования: ");
System.out.println(String.join("\n", note));
System.out.println();
}
if (count == 3){
// Здесь я пытался сделать, но возникли проблемы с переобразованием
System.out.println("Выберите номер задачи которую хотите удалить");
String indexInput = scanner.next();
note.remove(indexInput);
}
if (count == 0){
break;
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Integer indexInput = Integer.valueOf(scanner.nextLine()); // Преобразует String в Integer
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question