到目前为止,我已经在网上寻求帮助,但没有任何东西对我有用。这就是我现在所拥有的,你能告诉我它有什么问题吗?
导入 java.util.*;
class employeeProgram{
public static void main(String[] args){
for (int count = 0; count < 1; ){
Scanner input = new Scanner(System.in);
ArrayList<String> employeeNames = new ArrayList<String>();
String commnd;
print("What would you like to do? (Add, Remove, List, Exit): ");
commnd = input.next();
if ("Add".equals(commnd)){
print("Enter the name of the employee you'd like to add to the list: ");
employeeNames.add(input.next());
} else if ("Remove".equals(commnd)){
print("Enter the name of the employee you'd like to remove from the list: ");
employeeNames.remove(input.next());
} else if ("List".equals(commnd)){
for (int j = 0; j < employeeNames.size(); j++){
println(employeeNames.get(j));
println(j);
}
//println(employeeNames);
} else if ("Exit".equals(commnd)){
input.close();
break;
} else {
println("Invalid command.");
}
}
}
public static void println(Object x){
System.out.println(x);
}
public static void print(Object x){
System.out.print(x);
}
}
for 循环还没有开始,我知道很多,因为“println(j)”也没有工作。当我尝试我已经注释掉的部分时,我从输入列表中得到的只是“[]”,没有别的。我是初学者,这是我第一个使用 ArrayLists 的程序,所以提前感谢任何决定帮助我的人:)