Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- public class ArrayListUpr {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- ArrayList<String> MyList = new ArrayList<String>();
- System.out.println("Input <add> <rem> <prn> <end>");
- String answer = scan.nextLine();
- while(!answer.contains("end")){
- if(answer.equals("add")){
- System.out.println("Input name: ");
- String name = scan.nextLine();
- MyList.add(name);
- }
- if(answer.equals("rem")){
- System.out.println("Input number: ");
- int index = scan.nextInt();
- if(index >= 0 && index <= MyList.size()){
- MyList.remove(index - 1);
- }else{
- System.out.println("Wrong index!!");
- }
- }
- if(answer.equals("prn")){
- System.out.println("My list: " + MyList);
- }
- System.out.println("Input <add> <rem> <prn> <end>");
- answer = scan.nextLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement