Modify the code to find and remove the highest and lowest values from the ArrayL
ID: 3933007 • Letter: M
Question
Modify the code to find and remove the highest and lowest values from the ArrayList, and then print the remaining values in the ArrayList.
Loopy2.java
import java.util.ArrayList;
import java.util.Scanner;
public class Loopy2 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
ArrayList<Integer> list = new ArrayList<Integer>();
System.out.println("Enter an arbitrary number of integers: ");
for(;;){
String s = scan.next();
if(s.equalsIgnoreCase("Q")){
break;
}
else{
list.add(Integer.valueOf(s));
}
}
System.out.println("ArrayList values are: ");
for(int i=0;i < list.size(); i++){
System.out.println(list.get(i));
}
}
}
Explanation / Answer
class Loopy { public static void main(String args[]){ Scanner s = new Scanner(System.in); System.out.print("Enter no. of elements you want in array:"); n = s.nextInt(); int a[] = new int[n]; System.out.println("Enter all the elements:"); for(int i = 0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.