import java.util.HashSet;
import java.util.Set;
/*
Greater than 10? You're not a good fit for us
*/
public class Solution {
public static HashSet<Integer> createSet() {
// write your code here
HashSet<Integer> hs=new HashSet<Integer>();
hs.add(1);
hs.add(2);
hs.add(3);
hs.add(4);
hs.add(5);
hs.add(6);
hs.add(7);
hs.add(8);
hs.add(9);
hs.add(10);
hs.add(11);
hs.add(12);
hs.add(13);
hs.add(14);
hs.add(15);
hs.add(16);
hs.add(17);
hs.add(18);
hs.add(19);
hs.add(20);
return hs;
}
public static HashSet<Integer> removeAllNumbersGreaterThan10(HashSet<Integer> set) {
what's wrong with my code..I feel so confusing
Under discussion
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
Echapman
5 June 2020, 19:59
The removeAllNumbersGreaterThan10 method is probably what you should have pasted. That's where you've probably tripped up at.
0
Odhran
24 May 2020, 21:38
Don't get disheartened. Actually what would help in addition to this course is studying algorithm theory, collections are tricky, a good understanding of the Big 'O' notation helps. Anyways the 1st bit looks ok, you need to add the following to complete the task
public static HashSet<Integer> removeAllNumbersGreaterThan10(HashSet<Integer> set) {
Iterator<Integer> set1 = hs.iterator(); //cycle through the set
while (set1.hasNext()) { // while loop
if(set1.next() > 10 ) // questions "is the current value more than 10?"
{
set1.remove(); // if yes it remove that value, if no the loop continues checking each value until until its cycled through the set
}
}
return set; // return the amended set now all value will be less than 10
}
0
Gellert Varga
24 May 2020, 19:41
Where is the code continuation?
Where is the removeAllNumbersGreaterThan10() method?
In the help section, when you have a question, there is a function, there is a button with which you can attach the whole program. (No need for Ctrl+C and Ctrl+V.)
That's much better.
I see better what it's all about.
Please use that!
0