Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with the following instuctions below. I realize there is a solution on Chegg already however when the Union is printed it's not

I need help with the following instuctions below. I realize there is a solution on Chegg already however when the Union is printed it's not in numerical order, which I need it to be. As well I can only import java.util.Scanner; I have also attached a partial code of how my professor started his code. Thank you for any help in advance!

**Instructions**

Write a Java program that uses one-dimensional arrays to implement finite sets and set operations union, difference, and intersection. Specific requirements:

1. You should name your program as a4sets.java.

2. Elements of a set are integers from 1 to 20.

3. Use 0 as the end of a set. See examples below. 4. Prompt user to enter two sets A and B and calculate A union B, A intersection B, and A difference B.

Here is a sample input and output: Enter elements of set A: 2 4 6 7 9 0

Enter elements of set B: 1 3 5 7 9 10 18 0 Union of A and B is: 1, 2, 3, 4, 5, 6, 7, 9, 10, 18 Intersetion of A and B is: 7, 9

Difference of A and B is: 2, 4, 6

**Sample code from professor on how he started his, need to look similar**

import java.util.Scanner; public class chenSets {

public static void main(String[] args) { System.out.println("Enter integers between 1 and 20 as set A (use 0 to end input): ");

Scanner input = new Scanner(System.in);

int element=input.nextInt();

int[] setA = new int[21];

while (element !=0) {

setA[element]=1;

element = input.nextInt();

}

System.out.print(" *** Set A is:");

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

Building Database Driven Catalogs

Authors: Sherif Danish

1st Edition

0070153078, 978-0070153073

More Books

Students also viewed these Databases questions

Question

Can I learn what I need to know in the time available to me?

Answered: 1 week ago