Write a public static method named allLessThanMean that will take an ArrayList as an argument. This method will return an ArrayList. When called and passed anArrayList, this method will return an ArrayList containing all the elements in the argument ArrayList that are less than the average of all the values in the argument ArrayList. The values in the returned ArrayList must be in the same order as they are in the argument ArrayList. Here are some examples: Example 1 Given: ArrayList myList = new ArrayList(); with these values {1, 2, 3, 4, 5}; allLessThanMean(myList) should return an ArrayList with these values {1, 2} Example 2 Given: ArrayList myList = new ArrayList(); with these values {3, 7, 6, 2, 9, 0, 4, 8}; allLessThanMean(myList) should return an ArrayList with these values {3, 2, 0, 4} Example 3 Given: ArrayList myList = new ArrayList(); with these values {1, 1, 1}; allLessThanMean(myList) should return an ArrayList with these values { } Helpful Info: You should write a main method to call and test your required method before you submit for grading
Write a public static method named allLessThanMean that will take an ArrayList<Integer> as an argument. This method will return an ArrayList<Integer>. When called and passed anArrayList, this method will return an ArrayList containing all the elements in the argument ArrayList that are less than the average of all the values in the argument ArrayList. The values in the returned ArrayList must be in the same order as they are in the argument ArrayList.
Here are some examples:
Example 1
Given: ArrayList<Integer> myList = new ArrayList<Integer>(); with these values {1, 2, 3, 4, 5};
allLessThanMean(myList) should return an ArrayList<Integer> with these values {1, 2}
Example 2
Given: ArrayList<Integer> myList = new ArrayList<Integer>(); with these values {3, 7, 6, 2, 9, 0, 4, 8};
allLessThanMean(myList) should return an ArrayList<Integer> with these values {3, 2, 0, 4}
Example 3
Given: ArrayList<Integer> myList = new ArrayList<Integer>(); with these values {1, 1, 1};
allLessThanMean(myList) should return an ArrayList<Integer> with these values { }
Helpful Info:
- You should write a main method to call and test your required method before you submit for grading
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images