Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago