Array Simulation

Category: Simulation
Author: Stuart Reges
Book Chapter: 7.1
Problem: Array Simulation
  You are to simulate the execution of a method
   that manipulates an array of integers.  Consider the following method:

        public static void mystery(int[] list) {
            for (int i = 2; i < list.length; i++) {
                list[i] = list[i] - list[i - 1];
            }
        }

   In the left-hand column below are specific lists of integers.  You are to
   indicate in the right-hand column what values would be stored in the list
   after method mystery executes if the integer list in the left-hand column
   is passed as a parameter to mystery.

        Original List                   Final List
        ------------------------------------------------------------

        {8, 4}                          ____________________________

        {20, 30, 40}                    ____________________________

        {1, 2, 3, 4, 5}                 ____________________________

        {5, 5, 5, 5}                    ____________________________

        {10, 20, 30, 40, 50}            ____________________________
1) {8, 4}
2) {20, 30, 40}
3) {1, 2, 3, 4, 5}
4) {5, 5, 5, 5}
5) {10, 20, 30, 40, 50}