very very simple task BUT..... does not pass the test.... may be test checker is broken (that it's not tuned correctly is obviously)

public static HashSet<Integer> createSet()
    {
        HashSet<Integer> set = new HashSet<>();

        Collections.addAll(set, 10, 3, 45, 2, 5, 6, 7, 8, 34, 12,
                                4, 1, 13, 36, 78, 12, 17, 9, 20);

        return set;
    }

public static HashSet<Integer> removeAllNumbersMoreThan10(HashSet<Integer> set)
{
    Iterator iterator = set.iterator();
    while(iterator.hasNext())
    {
        int x = (Integer) iterator.next();
        if(x > 10)
            iterator.remove();
    }

    return set;
}

asked 07 Mar, 01:18

Dmitry%20Sky's gravatar image

Dmitry Sky
112
accept rate: 0%


Passed test.

public class Solution
{
    public static HashSet<Integer> createSet()
    {
        HashSet<Integer> set = new HashSet<Integer>();
        for(int i=0; i < 20; i++){
            set.add(i);
        }
        return set;
    }

    public static HashSet<Integer> removeAllNumbersMoreThan10(HashSet<Integer> set)
    {
        Iterator<Integer> it = set.iterator();
        while(it.hasNext()){
            if(it.next() > 10){
                it.remove();
            }
        }
        return set;
    }
}
link

answered 26 May, 11:33

Igor's gravatar image

Igor
112
accept rate: 0%

edited 26 May, 11:33

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×10

Asked: 07 Mar, 01:18

Seen: 335 times

Last updated: 26 May, 11:33