Question
Hi guys, I have this code that prints out AB, AB, and complements of B'. I am trying to add the fourth function, which is
Hi guys, I have this code that prints out AB, AB, and complements of B'. I am trying to add the fourth function, which is to print out this: "(AB) x A" (or I believe this is the Cartesian product rule). How do I add that code in? Thank you.
CODE:
import java.util.Scanner;
public class sets
{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
int n1,n2;
System.out.print("Enter SET A range: ");
n1=input.nextInt();
System.out.print("Enter SET B range: ");
n2=input.nextInt();
int[] A = new int[n1];
int[] B = new int[n2];
int[] AintersectionB = new int[n1+n2];
int[] AunionB = new int[n1+n2];
int[] Bcompliment = new int[n1+n2];
int index1=0,index2=0,index3=0;
System.out.println("Please enter integers for SET A:");
for(int i=0;i { A[i] = input.nextInt(); if(i>=1) { int flag=1; for(int j=0;j { if(A[i]==AunionB[j]) { flag=0; } } if(flag==1) { AunionB[index1++]=A[i]; } } else { AunionB[index1++]=A[i]; } } System.out.println("Please enter integers for SET B:"); for(int i=0;i { B[i] = input.nextInt(); } //A Union B for(int i=0;i { int flag=1; for(int j=0;j { if(B[i]==AunionB[j]) { flag=0; } } if(flag==1) { AunionB[index1++]=B[i]; } } //A Intersection B for(int i=0;i { int flag=1; for(int j=0;j { if(A[i]==B[j]) { flag=0; } } if(flag==0) { if(i>=1) { int flag1=1; for(int k=0;k { if(A[i]==AintersectionB[k]) { flag1=0; } } if(flag1==1) { AintersectionB[index2++]=A[i]; } } else { AintersectionB[index2++]=A[i]; } } } //B complement; int p=0; for(int i=0;i<=9;i++) { int flag=1; for(int j=0;j { if(i==B[j]) { flag=0; } } if(flag==1) { if(p==1) { int flag1=1; for(int k=0;k { if(i==Bcompliment[k]) { flag1=0; } } if(flag1==1) { Bcompliment[index3]=i; index3=index3+1; } } else { Bcompliment[index3++]=i; p=1; } } } System.out.println("A Union B:"); for(int i=0;i { System.out.println(AunionB[i]); } System.out.println("A intersection B:"); for(int i=0;i { System.out.println(AintersectionB[i]); } System.out.println("B complement values:"); for(int i=0;i { System.out.println(Bcompliment[i]); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started