PBLJ 2.2
PBLJ 2.2
2 )
Question : Playing cards during travel is a fun filled experience. For this game they wanted to collect
all four unique symbols. Can you help these guys to collect unique symbols from a set of cards?
Create Card class with attributes symbol and number. From our main method collect each card
details (symbol and number) from the user.
Collect all these cards in a set, since set is used to store unique values or objects.
Once we collect all four different symbols display the first occurrence of card details in alphabetical
order.
Program / Code :
package worksheet2;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
System.out.println("Enter a card:");
card.setNumber(sc.nextInt());
sc.nextLine();
set.add(card);
sc.close();
Output :
Before compiling the code :
After compiling the code :