Question: Integer arrays firstArray and secondArray are read from input, each containing four elements. If an element in firstArray is less than or equal to the

Integer arrays firstArray and secondArray are read from input, each containing four elements. If an element in firstArray is less than or equal to the corresponding element in secondArray, then replace the element in firstArray with 0. Otherwise, add 2 to the element in firstArray.
Ex: If the input is:
4031472419273541
then the output is:
4233490
import java.util.Scanner;
public class ArrayComparison {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
final int NUM_VALS =4;
int[] firstArray = new int[NUM_VALS];
int[] secondArray = new int[NUM_VALS];
int i;
for (i =0; i < NUM_VALS; ++i){
firstArray[i]= scnr.nextInt();
}
for (i =0; i < NUM_VALS; ++i){
secondArray[i]= scnr.nextInt();
}
/* Your code goes here */
for (i =0; i < firstArray.length; ++i){
System.out.print(firstArray[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!