A13. Exercises 1

  1. Write a function that returns an ArrayList with 8 random numbers from 10 to 30 (inclusive).

  2. Write a function to return the mathematical average of all of the numbers in an ArrayList<Integer>. Use double as the return type.

  3. (mkAL) Given an array of int, return an ArrayList<Integer> containing the same elements.

  4. (add35) Insert a single 3 before every 5 in the input.

     public static void add35 (ArrayList<Integer> nums)
    
  5. (kill46) When you find a 4 followed by 6, remove the next item from the array list.

     public static void kill46 (ArrayList<Integer> nums)
    

Tester code

public static void test35 () {
    ArrayList<Integer> demo = new ArrayList<>();
    demo.add(1);
    demo.add(3);
    demo.add(5);
    demo.add(7);
    add35(demo);
    System.out.println(demo);
}