0% found this document useful (0 votes)
24 views1 page

Set Exercitii

Uploaded by

Eduard Manea
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views1 page

Set Exercitii

Uploaded by

Eduard Manea
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.util.

HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
public class SetCollectionColor {
public static void main(String[] args) {
Set<String> colors = new HashSet<>();
System.out.println("Introduceti numarul de culori: ");
Scanner scan = new Scanner(System.in);
int numberColor = scan.nextInt();
scan.nextLine();
while (numberColor-- > 0){
System.out.println("Introdu culoarea.Mai ai: " + (numberColor+1));
String colorName = scan.nextLine();
colors.add(colorName);
}
System.out.println("Culorile introduse sunt: ");
for (String color:colors){
System.out.println(color);
}
System.out.println("Stergeti o culoare: ");
String removeColor = scan.nextLine();
if (colors.contains(removeColor)){
colors.remove(removeColor);
}
System.out.println("Culorile ramase sunt: ");
for (String newColor:colors){
System.out.println(newColor);
}
System.out.println("Culorile au fost sortate: ");
Set<String> sortColor = new TreeSet<>(colors);
for (String color:sortColor){
System.out.println(color);
}
}
}

You might also like