Remove Three
An ArrayList has an Integer 3 and several other numbers in it. What is the best way to remove that Integer 3?
Scenario 1 You know the location of the Integer 3 in the list.
Scenario 2 You don’t know the location of the Integer 3 in the list.
Problem statement
Modify the given scaffolding code so that you handle Scenario 1. If the desired integer is properly removed, the sum of all elements in the list will be matched with what the test case expects.
import java.io.*;
import java.util.*;
public class JavaTutorial{
public static void main(String[] args){
List<Integer> numbers = new ArrayList<Integer>();
numbers.add(1);
numbers.add(2);
numbers.add(3);
numbers.add(3);
numbers.add(4);
numbers.add(3);
System.out.println("ArrayList contains : " + numbers);
numbers.remove(3);
System.out.println("ArrayList contains : " + numbers);
int sum = 0;
for (int i: numbers)
sum += i;
System.out.println (sum);
}
}
This is my question and Sample Code to edit with.
Can anyone help me solve the problem?