Simulation
Category: Simulation
Author: Stuart Reges
Book Chapter: 7.1
Problem: 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 = 0; i < list.length - 1; 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 Original List Final List ------------------------------------------------------------ (5) ____________________________ (4, 7) ____________________________ (2, 3, 4) ____________________________ (2, 4, 6, 8) ____________________________ (9, 7, 5, 3, 1) ____________________________
1) (5)
2) (4, 7)
3) (2, 3, 4)
4) (2, 4, 6, 8)
5) (9, 7, 5, 3, 1)