Question: Integer arrays arrayA and arrayB are read from input, and each store 2 elements . For each index from 0 to NUM _ VALS, compare

Integer arrays arrayA and arrayB are read from input, and each store
2
elements. For each index from
0
to NUM
_
VALS, compare the element at the index in arrayA with the element at the same index in arrayB. Store the larger element in the array largerNums. Ex: If the input is:
1
2
3
1
1
7
2
7
then the output is:
1
7
3
1
import java.util.Scanner; public class ArrayComparison
{
public static void main
(
String
[
]
args
)
{
Scanner scnr
=
new Scanner
(
System
.
in
)
; final int NUM
_
VALS
=
2
; int
[
]
arrayA
=
new int
[
NUM
_
VALS
]
; int
[
]
arrayB
=
new int
[
NUM
_
VALS
]
; int
[
]
largerNums
=
new int
[
NUM
_
VALS
]
; int i; for
(
i
=
0
; i
<
NUM
_
VALS;
+
+
i
)
{
arrayA
[
i
]
=
scnr
.
nextInt
(
)
;
}
for
(
i
=
0
; i
<
NUM
_
VALS;
+
+
i
)
{
arrayB
[
i
]
=
scnr
.
nextInt
(
)
;
}
/
*
Your code goes here
*
/
for
(
i
=
0
; i
<
largerNums.length;
+
+
i
)
{
System.out.print
(
largerNums
[
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!