Write a Java program to work with two arrays and perform operations on them. Your program should have 2 methods: int[] union (int[] al, int[] a2): takes two integer arrays and returns a new integer array consisting of all ints that appear in either al or a2. The returned array should be appropriately sized and should contain any duplicate ints since everything from both a1 and a2 should be in there. The returned array should not have any emp spots and should be sorted numerically. intl intersection (int[] al. int[] a2): takes two integer arrays and returns ● ●

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Write a Java program to work with two arrays and perform operations on them.
Your program should have 2 methods:
int[] union (int[] al, int[] a2): takes two integer arrays and returns a new
integer array consisting of all ints that appear in either a1 or a2. The returned array
should be appropriately sized and should contain any duplicate ints since everything
from both a1 and a2 should be in there. The returned array should not have any empty
spots and should be sorted numerically.
●
●
int[] intersection (int[] al, int[] a2): takes two integer arrays and returns a
new integer array consisting of all ints that appear in both a1 and a2. The returned array
should be appropriately sized and sorted numerically, and it should not contain any
duplicate ints or empty spots.
For example, when a1 = {1,2,3,4,5} and a2 {1,5,6,7,8}, union (al, a2) will return
{1,1,2,3,4,5,5,6,7,8} and intersection (al, a2) will return {1,5}.
=
Provide the following menu using a do..while loop in the main method to the user.
1. Union
2. Intersection
3. Exit
Before the menu pops up for the user, the main method should collect the input for the 2
arrays and create the arrays. After the user picks a menu choice, the main method should call
the appropriate method to do the work requested. Since these methods return new arrays to
the caller, the printing of the output of the new array should also be done by the main method.
Transcribed Image Text:Write a Java program to work with two arrays and perform operations on them. Your program should have 2 methods: int[] union (int[] al, int[] a2): takes two integer arrays and returns a new integer array consisting of all ints that appear in either a1 or a2. The returned array should be appropriately sized and should contain any duplicate ints since everything from both a1 and a2 should be in there. The returned array should not have any empty spots and should be sorted numerically. ● ● int[] intersection (int[] al, int[] a2): takes two integer arrays and returns a new integer array consisting of all ints that appear in both a1 and a2. The returned array should be appropriately sized and sorted numerically, and it should not contain any duplicate ints or empty spots. For example, when a1 = {1,2,3,4,5} and a2 {1,5,6,7,8}, union (al, a2) will return {1,1,2,3,4,5,5,6,7,8} and intersection (al, a2) will return {1,5}. = Provide the following menu using a do..while loop in the main method to the user. 1. Union 2. Intersection 3. Exit Before the menu pops up for the user, the main method should collect the input for the 2 arrays and create the arrays. After the user picks a menu choice, the main method should call the appropriate method to do the work requested. Since these methods return new arrays to the caller, the printing of the output of the new array should also be done by the main method.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Adjacency Matrix
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education