/
kanisavi
/
Course_List
Обзор
Документация
Войти
/
kanisavi
/
Course_List
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Main.java
78 строк
3 KB
Карина Басова
create Main.java
27 дек 2025, 19:15
27 дек 2025, 19:15
f355e73
Код
Авторство
О чём код?
import java.util.ArrayList; import java.util.Iterator; import java.util.Scanner; public class Main { public static void main(String[] args) { ArrayList<String> toDoList = new ArrayList<>(); while (true) { menu(); Scanner scanner = new Scanner(System.in); String input = scanner.nextLine(); int operation = Integer.parseInt(input); if (operation == 0) break; if (operation == 1) { System.out.print("Введите название задачи: "); toDoList.add(scanner.nextLine()); System.out.println("Добавлено!"); showList(toDoList); } if (operation == 2) { showList(toDoList); } if (operation == 3) { System.out.print("Введите номер для удаления: "); int index = Integer.parseInt(scanner.nextLine()); if (index > 0 && index <= toDoList.size()) { toDoList.remove(index - 1); System.out.println("Удалено!"); } else { System.out.println("Нет задачи с таким номером!"); } showList(toDoList); } if (operation == 4) { System.out.print("Введите задачу для удаления: "); String task = scanner.nextLine(); if (toDoList.remove(task)) { System.out.println("Удалено!"); } else { System.out.println("Нет такой задачи!"); } showList(toDoList); } if (operation == 5) { System.out.print("Введите ключевое слово для удаления задачи: "); String keyword = scanner.nextLine(); Iterator<String> it = toDoList.iterator(); while (it.hasNext()) { String s = it.next(); if (s.contains(keyword)) { it.remove(); } } showList(toDoList); } } } public static void menu() { System.out.println("Выберите операцию:"); System.out.println("0. Выход из программы"); System.out.println("1. Добавить дело"); System.out.println("2. Показать дела"); System.out.println("3. Удалить дело по номеру"); System.out.println("4. Удалить дело по названию"); System.out.println("5. Удалить дела по ключевому слову"); System.out.print("Ваш выбор: "); } public static void showList(ArrayList<String> list) { System.out.println("Ваш список дел: "); for (int i = 1; i <= list.size(); i++) { System.out.print(i + ". " + list.get(i - 1) + "\n"); } System.out.println(); } }