Write a loop that sets newScores to oldScores shifted once left, with element 0 copied to the end. Ex: If oldScores = {10, 20, 30, 40}, then newScores = {20, 30, 40, 10}. Note: These activities may test code with different test values. This activity will perform two tests, the first with a 4-element array (newScores = {10, 20, 30, 40}), the second with a 1-element array (newScores = {199}).

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;

/* Your solution goes here */

for (i = 0; i < SCORES_SIZE; ++i) {
System.out.print(newScores[i] + " ");
}
System.out.println();

return;
}

Respuesta :

Answer:

The code to this question can be given as:

Code:

int lastVector = newScores.size() -1; //define variable lastVector that holds updated size of newScores.

newScores = oldScores; //holds value.

for (i = 0; i < SCORES_SIZE - 1; i++) //define loop.

{  

newScores.at(i) = newScores.at(i+1); //holds value in newScores.

}

newScores.at(lastVector) = oldScores.at(0); //moving first element in last.

Explanation:

  • In the given C++ program there are two vector array is defined that are "oldScores and newScores". The oldScores array holds elements that are "10, 20, 30, 40".
  • In the above code, we remove the array element at first position and add it to the last position. To this process, an integer variable "lastVector" is defined.  
  • This variable holds the size of the newScores variable and uses and assigns all vector array elements from oldScores to newScores. In the loop, we use the at function the removes element form first position and add in the last position.
  • Then we use another for loop for print newScores array elements.  

The program illustrates the use of loops.

In programming, loops are used for operations that are to be repeated  

Replace /* Your solution goes here */  with the following lines of code

for (i = 1; i < SCORES_SIZE; ++i) {

newScores[i-1] = oldScores[i];

}

newScores[3] = oldScores[0];

The above code segment with comments is as follows:

//This iterates through the oldScores array

for (i = 1; i < SCORES_SIZE; ++i) {

//This moves the second element to the fourth elements of oldScores to newScores

newScores[i-1] = oldScores[i];

}

//This moves the first element of oldScores to the last of newScores

newScores[3] = oldScores[0];

At the end of the iteration, the elements are shifted to newScore

Read more about loops at:

https://brainly.com/question/18269390