Question: Integer numValues is read from input, representing the number of floating - point numbers to be read next. Then, the remaining numbers are read and

Integer numValues is read from input, representing the number of floating-point numbers to be read next. Then, the remaining numbers are read and stored into array benefitsList. Write a loop that assigns array modifiedList with benefitsList's elements shifted to the left by one index. The element at index 0 of benefitsList should be copied to the end of modifiedList.
Ex: If the input is:
3
370.0250.0210.0
then the output is:
Original benefits: 370.0250.0210.0
Updated benefits: 250.0210.0370.0
import java.util.Scanner;
public class ArrayModification {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
double[] benefitsList;
double[] modifiedList;
int numValues;
int i;
numValues = scnr.nextInt();
benefitsList = new double[numValues];
modifiedList = new double[numValues];
for (i =0; i < benefitsList.length; ++i){
benefitsList[i]= scnr.nextDouble();
}
/* Your code goes here */
System.out.print("Original benefits: ");
for (i =0; i < benefitsList.length; ++i){
System.out.printf("%.1f ", benefitsList[i]);
}
System.out.println();
System.out.print("Updated benefits: ");
for (i =0; i < modifiedList.length; ++i){
System.out.print(modifiedList[i]+"");
}
System.out.println();
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!