Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a public static method called smaller Of Two that takes two Array List as

ID: 3828892 • Letter: W

Question

Write a public static method called smaller Of Two that takes two Array List as parameters, and returns another Array List. The returned Array List should have the same size as the two array lists that are passed in. The elements of the returned Array List should be the smaller of 2 elements from the original Array List. For example, if the values {1, 8, 4} and {4, 5, 6} are passed in, smaller Of Two should return the list {1, 5, 4}. You may ignore the case where the original Array Lists are not the same size.

Explanation / Answer

Hi, Please find my implementation.

Please let me know in case of any issue.

import java.util.ArrayList;

public class ArrayListMethod {

  

   public static void awesomeArray(char[][] a){

      

      

       String awesome = "AWESOME";

       int n = awesome.length();

      

       int count = 0;

      

       for(int i=0; i<a.length; i++){

           for(int j=0; j<a[i].length; j++){

               count = (count + 1)%n;

               a[i][j] = awesome.charAt(count);

           }

       }

   }

  

   public static ArrayList<Double> smallerOfTwo(ArrayList<Double> list1, ArrayList<Double> list2){

      

       ArrayList<Double> result = new ArrayList<>();

      

       int n1 = list1.size();

       int n2 = list2.size();

      

       for(int i=0; i<n1 && i<n2; i++){

          

           double l1 = list1.get(i);

           double l2 = list2.get(i);

          

           double small = l1 < l2 ? l1 : l2;

          

           result.add(small);

       }

      

       return result;

   }

  

   public static void main(String[] args) {

      

       ArrayList<Double> l1 = new ArrayList<Double>();

       ArrayList<Double> l2 = new ArrayList<Double>();

      

       l1.add(1.0);

       l1.add(8.0);

       l1.add(4.0);

      

       l2.add(4.0);

       l2.add(5.0);

       l2.add(6.0);

      

       System.out.println(smallerOfTwo(l1, l2));

   }

}

/*

sample run:

[1.0, 5.0, 4.0]

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote