Respuesta :
Java program that load data on structure type ArrayList, adds, removes, replaces elements from the list according to command. The output and the code image is attached.
Java code
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
ArrayList<Integer> lsta = new ArrayList();
Scanner sc = new Scanner(System.in);
- //Define variables
int i;
int vlu;
int vlu1;
int comd;
do {
do {
- //Input comand
System.out.print("Comand: ");
comd = sc.nextInt();
} while (!(comd>=0 & comd<=3));
switch (comd) {
case 0 :
System.out.print("Value: ");
vlu = sc.nextInt();
- //add the list to the end of the ArrayList
lsta.add(vlu);
break;
case 1:
do {
System.out.print("Value 1: ");
vlu = sc.nextInt();
} while (vlu > lsta.size());
System.out.print("Value 2: ");
vlu1 = sc.nextInt();
- //reset the element at given index
lsta.set(vlu,vlu1);
break;
case 2:
do {
System.out.print("Value: ");
vlu = sc.nextInt();
} while (vlu > lsta.size());
- //remove an element at a particular index
lsta.remove(vlu);
break;
}
} while (!(comd==3));
- //Print the contents of the arraylist and exit the program
System.out.println("The contents of the arraylist:" + lsta);
}
}
To learn more about Java method ArrayList see: https://brainly.com/question/23189171
#SPJ4

