For the given problem, define the size equal to 4 since four scores are given. Now, create two arrays: one for storing old score values and second for storing new score values. After this, assign old scores in an array and then create a loop that will shift the old score from second element until the one less than the size . Now, display the old scores and new scores as shown in output.
Further explanation:
Code:
The Java code to set the new scores from given old scores is as given below:
//Define the StudentScore class
public class StudentScores
{
//main method
public static void main(String[] args)
{
//Define final variable
final int SCORES_SIZE=4;
//Create two array
int[] oldScores = new int[SCORES_SIZE];
int[] newScores = new int[SCORES_SIZE];
//Declare a variable
int i = 0;
//Assign values to array
oldScores[0]=10;
oldScores[1]=20;
oldScores[2]=30;
oldScores[3]=40;
/*Your solution goes here*/
int firstOldScore=oldScores[0];
//Run for loop to shift the old score from second element until the one less than the size
for(int index=0;index<SCORES_SIZE-1;index++)
{
//shift oldScores to newScores
newScores[index]=oldScores[index+1];
}
newScores[SCORES_SIZE-1]=firstOldScore;
System.out.println("oldScores:");
for(i=0;i<SCORES_SIZE;++i)
{
// Display the oldScores
System.out.print(oldScores[i]+" ");
}
System.out.println();
// Print the new scores
System.out.println("newScores:");
for (i=0;i<SCORES_SIZE;++i)
{
//Display newScores
System.out.print(newScores[i] + " ");
}
System.out.println();
return;
}
}
Output:
oldScores:
10 20 30 40
newScores:
20 30 40 10
Learn more:
1. How does coding work on computers? brainly.com/question/2257971
2. Prediction accuracy of a neural network depends on _______________ and ______________. brainly.com/question/10599832
Answer details:
Grade: College Engineering
Subject: Computer Science
Chapter: Java Programming
Keyword:
Java, input, output, programming, statements, char, int, variables, file, loop, old scores, new scores, array, size, variable, display