我是Java編程的新手。我想問我怎麼能插入/刪除用戶輸入到我生成的數組列表中。它應該顯示形成我已經有一個代碼的新的列表。但它不工作以及..這裏是我的代碼:按用戶輸入插入/刪除數組中的元素
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.*;
class New1 {
public static InputStreamReader r = new InputStreamReader (System.in);
public static BufferedReader inp = new BufferedReader(r);
public static void main (String args[]) throws Exception {
ArrayList employees = new ArrayList();
employees.add("A");
employees.add("B");
employees.add("C");
employees.add("D");
employees.add("E");
Scanner scan1 = new Scanner (System.in);
System.out.println ("Lists of Employees");
System.out.println ("What do you want to do?:");
System.out.println ("1 - Display list. \n2 - Insert New Name. \n3 - Delete an item. \n4 - Nothing." + "\n ");
int task = scan1.nextInt();
if (task==1) {
System.out.println ("Contents of Employees:" + employees);
} else if (task==2) {
do {
System.out.println("Current list is " + employees);
System.out.println("Add more? (y/n) ");
if (scan1.next().startsWith("y")) {
System.out.println("Enter : ");
employees.add(scan1.next());
} else {
break;
}
} while (true);
System.out.println("List is " + employees);
String[] arr = employees.toArray(new String[0]);
System.out.println("Array is " + Arrays.toString(arr));
}
}
我真的需要幫助這裏。 >。 <
「_but它不工作well_」 ISN」 t非常具體... – jlordo 2013-02-14 20:25:05
你的意思是不工作? – 2013-02-14 20:25:06
它現在做了什麼,它應該做什麼? – dutt 2013-02-14 20:30:22