You are on page 1of 1

package birthmonth;

import java.util.*;

public class BirthMonth {

public static void main(String[] args) {


Scanner input = new Scanner(System.in);
Set group1 = new HashSet();
Set group2 = new HashSet();
Set self = new HashSet();

for(int i = 1; i <= 3; i++) {


System.out.print("Enter birth month " + i + ": ");
group1.add(input.nextLine());
}

for(int n = 1; n <= 3; n++) {


System.out.print("Enter birth month " + n + ": ");
group2.add(input.nextLine());
}
System.out.println("Group 1:" + group1);
System.out.println("Group 2:" + group2);

System.out.print("Enter your Birth Month: ");


self.add(input.nextLine());

Set union = new HashSet(group1);


Set inter = new HashSet(group1);
Set diff = new HashSet(group1);
union.addAll(group2);
inter.retainAll(group2);
diff.removeAll(group2);
System.out.println("Union: " + union);
System.out.println("Intersection: " + inter);
System.out.println("Difference: " + diff);

if(group1.contains(self)&& group2.contains(self)) {
System.out.println("You have the same birth month with your
classmate!");
}
else {
System.out.println("You don't have the same birth month with your
classmate!");
}
}

You might also like