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

Integer numElements 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 wagesArray. Write a loop that assigns array rotatedArray with wagesArray's elements shifted to the left by one index. The element at index 0 of wagesArray should be copied to the end of rotatedArray.
Ex: If the input is:
3
250.5260.5220.5
then the output is:
Original wages: 250.5260.5220.5
Updated wages: 260.5220.5250.5
import java.util.Scanner;
public class ArrayModification {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
double[] wagesArray;
double[] rotatedArray;
int numElements;
int i;
numElements = scnr.nextInt();
wagesArray = new double[numElements];
rotatedArray = new double[numElements];
for (i =0; i < wagesArray.length; ++i){
wagesArray[i]= scnr.nextDouble();
}
/* Your code goes here */
System.out.print("Original wages: ");
for (i =0; i < wagesArray.length; ++i){
System.out.printf("%.1f ", wagesArray[i]);
}
System.out.println();
System.out.print("Updated wages: ");
for (i =0; i < rotatedArray.length; ++i){
System.out.print(rotatedArray[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!