Im having trouble creating this set calculator, it was working okay at one point but I somehow messed it all up and now it doesn't actually find the Union, intersection, difference and complement anymore. Also my +n just prints a 1 instead of the set they entered.
Could someone help me please? I probably did something extremely off :( Thanks.
import java.util.Set;
import java.util.HashSet;
import java.util.*;
import java.util.Scanner;
public class FinalProject4 {
public static void main(String args[]) {
String[] list;
Scanner sc = new Scanner(System.in);
Scanner sc2 = new Scanner(System.in);
Set<Integer> A = new HashSet<Integer>();
System.out.println("Enter set A: ");
A.addAll(Arrays.asList());
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
System.out.println("You entered " + n);
}
Set<Integer> B = new HashSet<Integer>();
System.out.println("Enter set B: ");
B.addAll(Arrays.asList());
int v = sc2.nextInt();
for (int i = 0; i < v; i++) {
System.out.println("You entered: " + v);
}
// To find union
Set<Integer> union = new HashSet<Integer>();
union.addAll(A);
union.addAll(B);
System.out.print("Union of the two Sets is: ");
System.out.println(union);
// To find intersection
Set<Integer> intersection = new HashSet<Integer>();
intersection.addAll(A);
intersection.retainAll(B);
System.out.print("Intersection of the two Sets is: ");
System.out.println(intersection);
// To find the difference
Set<Integer> difference = new HashSet<Integer>();
intersection.addAll(A);
difference.removeAll(B);
System.out.print("Difference of the two Sets is: ");
System.out.println(difference);
// To find the complement
Set<Integer> complement = new HashSet<Integer>();
complement.addAll(B);
complement.removeAll(A);
System.out.print("Complement of the two Sets is:");
System.out.println(complement);
}
}