Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Transaction Processing

Authors: Philip M. Lewis, Arthur Bernstein, Michael Kifer

1st Edition

0201708728, 978-0201708721

More Books

Students also viewed these Databases questions

Question

What output is produced by the following code fragment?

Answered: 1 week ago