Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.ArrayList;
- public class ArrayList_185 {
- public static void main(String[] args) {
- Scanner Input = new Scanner(System.in);
- ArrayList<String> MyList = new ArrayList<>();//създаване на арейлист
- //System.out.println("Please choose :: <add> <rem> <prn> <end> :");
- String choice = "";//Input.nextLine();
- while (!choice.contains("end")) {//край
- if (choice.equals("add")) {//добавяне
- String name = Input.next();
- MyList.add(name);
- }
- if ((choice.equals(("rem")))) {//премахване
- System.out.println("Input number:");
- int number = Input.nextInt();
- if (number > 0 && number <= MyList.size()) {
- MyList.remove(number - 1);
- }
- else{
- System.out.println("No such number:");
- }
- if (choice.equals("prn")) {
- System.out.println(MyList);
- }
- }
- System.out.println("Please choose :: <add> <rem> <prn> <end> :");
- choice = Input.nextLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment