Question: Integer arrays arr 1 and arr 2 are read from input, each containing three elements. If an element in arr 1 is less than or

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