Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN JAVA!!!! Write a method named intersection ( ) that takes two integer arrays (A, B) as arguments. Initialize an array C with N, -1

IN JAVA!!!!

Write a method named intersection( ) that takes two integer arrays (A, B) as arguments.

Initialize an array C with N, -1 values, where N is the length of the A or B array. (Assume A and B are the same length.)

If an integer x, is found in both array A and B, store this integer at the first available index (C[index] equals -1) within array C. Return array C to your main method and then print out its elements.

Test your method on the following arrays:

Test #1

A = [1, 2, 3, 4, 5]

B = [5, 4, 3, 2, 1]

=> C = [1, 2, 3, 4, 5]

Test #2

A = [2, 7, 3, 5, 8]

B = [4, 5, 2, 6, 7]

=> C = [2, 7, 5, -1, -1]

Test #3

[1, 2, 3, 4, 5]

[6, 7, 8, 9, 10]

=> C = [-1, -1, -1, -1, -1]

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_2

Step: 3

blur-text-image_3

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

Explain three potentially negative effects of social networking.

Answered: 1 week ago

Question

How did you feel about taking piano lessons as a child? (general)

Answered: 1 week ago