Question: TreeSet Given variables ( a , b , c ) , and ( d ) , perform the following steps: -

TreeSet
Given variables\(a,b,c\),and\(d\),perform the following steps:
-Declare a TreeSet of Integer called numbers.
-\(\quad\)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.
-\(\quad\)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;
\(\mathrm{a}=\mathrm{in}.\operatorname{next|nt}(\));
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:[]
TreeSet
Given variables \( a, b, c \), and \( d \), perform the following steps:
- Declare a TreeSet of Integer called numbers.
-\(\quad \) 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.
-\(\quad \) 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 statem
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;
\(\mathrm{a}=\mathrm{in}.\operatorname{next|nt}(\));
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: []
TreeSet Given variables \ ( a , b , c \ ) , and \

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!