What's new

Java Java map help!

Status
Not open for further replies.

Chunchunmaru

Eternal Poster
Joined
Aug 31, 2021
Posts
766
Reaction
288
Points
393
Eto ung code:
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:
IMG_20211212_163623.jpg

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

Last edited:
Status
Not open for further replies.

Similar threads

Back
Top