A13. Exercises 1
-
Write a function that returns an ArrayList with 8 random numbers from 10 to 30 (inclusive).
-
Write a function to return the mathematical average of all of the numbers in an
ArrayList<Integer>
. Usedouble
as the return type. -
(
mkAL
) Given an array ofint
, return anArrayList<Integer>
containing the same elements. -
(
add35
) Insert a single 3 before every 5 in the input.public static void add35 (ArrayList<Integer> nums)
-
(
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);
}