Question: Write a loop that sets each array element to the sum of itself and the next element, except for the last element which stays the
Write a loop that sets each array element to the sum of itself and the next element, except for the last element which stays the same. Be careful not to index beyond the last element. Ex:
Initial scores: 10, 20, 30, 40 Scores after the loop: 30, 50, 70, 40
The first element is 30 or 10 + 20, the second element is 50 or 20 + 30, and the third element is 70 or 30 + 40. The last element remains the same.
1 public class StudentScores 2 public static void main (String args) t String args) final int SCORES SIZE -4; int[] bonusScores new int[SCORES_SIZE]; int i 4 bonusScores[o] - 10; bonusScores [1] 20; bonusScores[2] 30; bonusScores[3] = 10 40; 12 13 14 15 16 17 18 Your solution goes here for ( );
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
