1. Write a program to accept inputs (10 numbers in a type int or double ) from t
ID: 3547745 • Letter: 1
Question
1. Write a program to accept inputs (10 numbers in a type int or double) from the user at the command line, and store in an ArrayList. (40 points)
1) These numbers must be inputted at the command line.
2) These numbers should be store in an ArrayList.
3) Find the large number in the list and display it.
4) Insert an element to the list at position 3.
5) Remove an element from the list at position 5.
6) Replace the value in the list at position 2
7) Display the new list.
Write a program to accept inputs (10 numbers in a type int or double) from the user at the command line, and store in an ArrayList. These numbers must be inputted at the command line. These numbers should be store in an ArrayList. Find the large number in the list and display it. Insert an element to the list at position 3. Remove an element from the list at position 5. Replace the value in the list at position 2 Display the new list.Explanation / Answer
import java.util.*;
public class arraylister
{
public static void main(String[] args)
{
// create an array list
ArrayList array = new ArrayList();
//These numbers must be inputted at the command line.
for(int i=0; i<args.length; i++)
//These numbers should be store in an ArrayList.
array.add(Integer.parseInt(args[i]));
//Find the large number in the list and display it.
System.out.println("Largest Element in array " + Collections.max(array));
//Insert an element to the list at position 3.
array.add(2,35);
//Remove an element from the list at position 5.
array.remove(4);
//Replace the value in the list at position 2
array.set(1,23);
// Display the new list.
System.out.println(array);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.