Question: Integer numValues is read from input, representing the number of integers to be read next. Then, the remaining integers are read and stored into array

Integer numValues is read from input, representing the number of integers to be read next. Then, the remaining integers are read and stored into array wagesList. Initialize the array halfList to be half the size of wagesList. Write a loop that iterates through halfList and:
If the corresponding element in the first half of wagesList is greater than 130, then assign the element in halfList with 0.
Otherwise, assign the element in halfList with the corresponding element in the first half of wagesList.
Ex: If the input is:
4
90170200120
then the output is:
Original wages: 90170200120
First half of the wages: 900
Note: Input array always has an even number of elements.
import java.util.Scanner;
public class Wage {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
int[] wagesList;
int[] halfList;
int numValues;
int i;
numValues = scnr.nextInt();
wagesList = new int[numValues];
for (i =0; i < wagesList.length; ++i){
wagesList[i]= scnr.nextInt();
}
/* Your code goes here */
System.out.print("Original wages: ");
for (i =0; i < wagesList.length; ++i){
System.out.print(wagesList[i]+"");
}
System.out.println();
System.out.print("First half of the wages: ");
for (i =0; i < halfList.length; ++i){
System.out.print(halfList[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!