Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //TEМА 16 Classwork 08.03.21//
- import java.util.ArrayList;
- import java.util.Scanner;
- public class UASD_2_080321 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- ArrayList<String> list = new ArrayList<>();
- String answer = "";
- while (!answer.equals("end")){
- System.out.println("Please, enter your choice: <add><rem><prn><end>");
- answer = sc.nextLine();
- if(answer.equals("add") ){
- System.out.println("Please, enter the name you'd like to add! ");
- String name = sc.nextLine();
- list.add(name);
- }else if(answer.equals("rem")){
- System.out.println("If you want to remove by number enter <num>. If you want to remove by name enter <name>! ");
- String choice = sc.nextLine();
- if(choice.equals("num")){
- System.out.println("Please, enter the number you'd like to remove! ");
- int number = sc.nextInt();
- list.remove(number - 1);
- }else if(choice.equals("name")){
- System.out.println("Please, enter the name you'd like to remove! ");
- String nametoremove = sc.nextLine();
- list.remove(new String(nametoremove));
- }
- }else if(answer.equals("prn")){
- System.out.println("Your list:" + list);
- }
- }
- System.out.println("The program has ended! ");
- }
- }
Add Comment
Please, Sign In to add comment