Chunchunmaru
Eternal Poster
- Joined
- Aug 31, 2021
- Posts
- 766
- Reaction
- 288
- Points
- 393
Eto ung code:
Eto yung dapat na output:
Bale yung last line nalang problema yung i didisplay kung my ka birthmonth ka, di ako alam ibabatong condition hayst
Up hehe, pa help po pls
JavaScript:
import java.util.Scanner;
import java.util.Set;
import java.util.HashSet;
import java.util.Collections;
public class BirthMonth {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Set<String> group1 = new HashSet<String>();
Set<String> group2 = new HashSet<String>();
Set<String> self = new HashSet<String>();
for(int n = 1; n <= 3; n++) {
System.out.print("Enter birth month " + n + ": ");
Collections.addAll(group1, scan.nextLine());
}
for(int n = 1; n <= 3; n++) {
System.out.print("Enter birth month " + n + ": ");
Collections.addAll(group2, scan.nextLine());
}
System.out.println("Group 1: " + group1);
System.out.println("Group 2: " + group2);
System.out.print("Enter your birth month: ");
Collections.addAll(self, scan.nextLine());
self = new HashSet<String>(group1);
self.addAll(group2);
System.out.println("Union: " + self);
//self = new HashSet<String>(group1);
self.retainAll(group2);
System.out.println("Intersection: " + self);
self = new HashSet<String>(group1);
self.removeAll(group2);
System.out.println("Difference: " + self);
//self = new HashSet<String>(group1);
if(group2.containsAll(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!");
}
}
}
Eto yung dapat na output:
Bale yung last line nalang problema yung i didisplay kung my ka birthmonth ka, di ako alam ibabatong condition hayst
Up hehe, pa help po pls
Attachments
-
You do not have permission to view the full content of this post. Log in or register now.
Last edited: