title: Java Modification of array elements using other elements-zybooks
body: <p>I am having problems with chapter 7.7 in zybooks with language in Java. The challenge activity is as stated:</p>
  
  <p>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: </p>
  
  <p>Initial scores:        10, 20, 30, 40</p>
  
  <p>Scores after the loop: 30, 50, 70, 40</p>
  
  <p>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. </p>
  
  <p>So this is the code it has provided with my code in it, I will say which part is my code:</p>
  
  <pre><code>public class StudentScores {
     public static void main (String [] args) {
        final int SCORES_SIZE = 4;
        int[] bonusScores = new int[SCORES_SIZE];
        int i = 0;
  
        bonusScores[0] = 10;
        bonusScores[1] = 20;
        bonusScores[2] = 30;
        bonusScores[3] = 40;
  
        if (SCORES_SIZE==0){
           System.out.println(""); 
        }
        else if (SCORES_SIZE==1){
           bonusScores[i]=bonusScores[i];
        }
        else{
           for (i=0; i&lt;SCORES_SIZE; ++i){
              if (i==3){
                 bonusScores[i]=bonusScores[i];  
              }
              else{
                 bonusScores[i]=bonusScores[i]+bonusScores[i+1];  
              }
           }
        }
  
  
        for (i = 0; i &lt; SCORES_SIZE; ++i) {
           System.out.print(bonusScores[i] + " ");
        }
        System.out.println();
  
        return;
     }
  }
  </code></pre>
  
  <p>So the only part that I can change and is therefor my code starts after the oldscores[3] part and ends after the else statement. So my problem is this is what the program is doing with my code:</p>
  
  <p>Testing for bonusScores = {10, 20, 30, 40}
  Your output
  30 50 70 40 
  check </p>
  
  <p>Testing for bonusScores = {199}
  Your output
  199 check</p>
  
  <p>Runtime error
  Program end never reached.
  This is commonly due to an invalid memory/array access or divide by 0.</p>
  
  <p>So I have no idea what it is doing what is causing the runtime error and therefor obviously do not know what to do as a result. If anyone has passed this, please let me know. I know there is a thread out there that is this one:</p>
  
  <p><a href="https://stackoverflow.com/questions/36001310/copying-and-modifying-array-elements">Copying and modifying array elements</a></p>
  
  <p>However, this thread is different from mine as that is actually the one I just completed without help of that thread. So please do not say possible repeat when it isn't. Thanks in advance. </p>