Taming the to-do tangle

Report a typo
Hey there! This problem might be a bit unpredictable, but give it a go and let us know how you do!
Implement a simple task list using ArrayList. The program should add tasks, remove tasks by index, and display the current list. Input format: operation (add/remove/display) followed by task description or index. For 'add', input the task. For 'remove', input the index. For 'display', no additional input is needed. Output the updated list after each operation.

Sample Input 1:

add
Buy groceries
remove
0
display

Sample Output 1:

[]

Sample Input 2:

add
Clean room
add
Finish homework
display

Sample Output 2:

[Clean room, Finish homework]
Write a program in Java 25
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
ArrayList<String> taskList = new ArrayList<>();
Scanner scanner = new Scanner(System.in);

while (scanner.hasNextLine()) {
String operation = scanner.nextLine();

if (operation.equals("add")) {

} else if (operation.equals("remove")) {

} else if (operation.equals("display")) {

}
}

scanner.close();
}
}

Create a free account to access the full topic