My objective is to write a loop that sets newScores to oldScores shifted once left, with element 0 copied to the end.
Edit: Here's my main problem, I initialized newScores[3] = oldScores[0];
but the thing is the for loop makes i = 4
when there's no oldScores[4] or newScores[4] but since I initialized newScores[3] to oldScores[0] it compiles and runs, but the problem is that [4] is not in the array at all. How do i get rid of this problem? I'm so close but so far away it's bugging me.
Example:
If oldScores = {10, 20, 30, 40}, then newScores = {20, 30, 40, 10}
Funny thing is I have the correct output but the learning website I'm using it tells me that I have the correct output but it also displays this "Runtime error (commonly due to an invalid array/vector access, divide by 0, etc.). Tests aborted.".
public class StudentScores {
public static void main (String [] args) {
final int SCORES_SIZE = 4;
int[] oldScores = new int[SCORES_SIZE];
int[] newScores = new int[SCORES_SIZE];
int i = 0;
oldScores[0] = 10;
oldScores[1] = 20;
oldScores[2] = 30;
oldScores[3] = 40;
newScores[3] = oldScores[0];
for(i=0; i<SCORES_SIZE-1; i++){
newScores[i] = oldScores[i +1];
}
for (i = 0; i < SCORES_SIZE; ++i) {
System.out.print(newScores[i] + " ");
}
System.out.println();
return;
}
}