You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
596 B
24 lines
596 B
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class HistoryCommand {
|
|
// 用List保存所有输入过的命令
|
|
private List<String> cmdList;
|
|
|
|
public HistoryCommand() {
|
|
cmdList = new ArrayList<>();
|
|
}
|
|
|
|
// 添加命令到历史
|
|
public void addCommand(String cmd) {
|
|
cmdList.add(cmd);
|
|
}
|
|
|
|
// 打印全部历史命令
|
|
public void showHistory() {
|
|
System.out.println("===== 命令历史记录 =====");
|
|
for (int i = 0; i < cmdList.size(); i++) {
|
|
System.out.println((i+1) + ". " + cmdList.get(i));
|
|
}
|
|
}
|
|
}
|