Question: Integer arrays originalArray and cleaningArray are read from input, each containing four elements. If an element in originalArray is negative, then replace the element in

Integer arrays originalArray and cleaningArray are read from input, each containing four elements. If an element in originalArray is negative, then replace the element in originalArray with the corresponding element in cleaningArray (which has only positive integers). Ex: If the input is: 33-3412-2520312945 then the output is: 33311245 import java.util.Scanner; public class ReplaceNegatives { public static void main(String args){ Scanner scnr = new Scanner(System.in); final int NUM_VALS =4; int originalArray = new int[NUM_VALS]; int cleaningArray = new int[NUM_VALS]; int i; for (i =0; i < NUM_VALS; ++i){ originalArray[i]= scnr.nextInt(); } for (i =0; i < NUM_VALS; ++i){ cleaningArray[i]= scnr.nextInt(); } for (i =0; i < originalArray.length; ++i){ System.out.print(originalArray[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 Programming Questions!