TreeSet
December 15, 2024 at 11:05 AM
Given variables a, b, c, and d, perform the following steps:
Declare a TreeSet of Integer called numbers.
Use a method to add each value from the provided variables a, b, c, and d to the numbers TreeSet.
Print the elements of the TreeSet numbers to the console, preceded by the string "Before: " in your print statement.
Use the clear() method to remove all the elements from the TreeSet called numbers.
Print the elements again after the TreeSet numbers is cleared. Add the string "After: " to the beginning of your print statement
import java.io.*;
import java.util.*;
public class CodingQuestion {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a, b, c, d;
a = in.nextInt();
b = in.nextInt();
c = in.nextInt();
d = in.nextInt();
/***** DO NOT CHANGE THE CODE ABOVE THIS LINE *****/
// WRITE YOUR CODE HERE
/***** DO NOT CHANGE THE CODE BELOW THIS LINE *****/
}
STDOUT
Expected STDOUT
Before: [20, 23, 25, 30]
After: []