Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- ArrayList<String> MyList = new ArrayList<>();
- String command = "";
- while(!command.contains("end")) {
- // ---- Добавяме ----
- if (command.contains("add")) {
- System.out.print("Please input name:");
- String name = scan.nextLine();
- MyList.add(name);
- }
- // ---- Премахваме ----
- if (command.contains("rem")) {
- System.out.println("Choose to remove : 1.By number or 2.By name");
- int choice = scan.nextInt();
- // Тук проверяваме дали избора е правилен
- if (choice == 1 || choice == 2) {
- // ---- Премахване по номер ----
- if (choice == 1) {
- System.out.print("Please input number:");
- int number = scan.nextInt();
- if (number > 0 && number <= MyList.size()) {
- MyList.remove(number - 1);
- } else {
- System.out.println("No such number !!!");
- }
- }
- //----- Премахване по име -----
- if (choice == 2) {
- System.out.println("Please input name: ");
- String Rname = scan.next();
- MyList.remove(String.valueOf(Rname));
- }
- } else {
- System.out.println("Wrong choice");
- }
- }
- // ---- Принтираме ----
- if(command.contains("prn")){
- System.out.println(MyList);
- }
- System.out.println("Please choose from : <add> <rem> <prn> <end>");
- command = scan.nextLine().toLowerCase();
- }
- System.out.println("Goodbye!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement