Modify the code to find and remove the highest and lowest va

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));
       }
   }
}

Solution

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; i < n ; i++) { a[i] = s.nextInt(); } int max = getMax(a); int min = getMin(a); for(i=0;i maxValue){ maxValue = inputArray[i]; } } return maxValue; } public static int getMin(int[] inputArray){ int minValue = inputArray[0]; for(int i=1;i
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 ja

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site