Greater than 10? You're not a good fit for us

  • 5
  • Locked
The Oddiozo transshipment center is looking for employees. The only requirement is this: employees must not have more than ten limbs (we don't know where this form of discrimination came from). We'll help them with a program that will create a set of numbers (Set ), add 20 different numbers, and then remove from the set all the numbers greater than 10.
You can't complete this task, because you're not signed in.
Comments (6)
  • Popular
  • New
  • Old
You must be signed in
DinoLevel 13 , Zagreb
10 January, 20:58
Can anyone tell me what doesn't work here? Thanks! package com.codegym.task.task08.task0814; import java.util.HashSet; import java.util.Set; import java.util.Iterator; /* Greater than 10? You're not a good fit for us */ public class Solution { public static HashSet<Integer> createSet() { // write your code here int[] a = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; HashSet<Integer> set = new HashSet<Integer>(); for(int aa: a) set.add(aa); return set; } public static HashSet<Integer> removeAllNumbersGreaterThan10(HashSet<Integer> set) { // write your code here for(Iterator<Integer> iterator = set.iterator(); iterator.hasNext();) { Integer aa = iterator.next(); if (aa > 10) set.remove(aa); } return set; } public static void main(String[] args) { } }
Guadalupe GagnonLevel 34 , Tampa
10 January, 21:13
hit the help button at the top and ask your question. Do not copy/paste your code...... use the slider:
Ed MaphisLevel 18 , Painesville
23 May, 19:26
Hmmm, I didn't know that.
Abhishek RangariLevel 22 , Nagpur
28 October 2018, 18:19
Be sure that the removeAllNumbersGreaterThan10 method works with sets of any size. ? public static HashSet<Integer> removeAllNumbersGreaterThan10(HashSet<Integer> set) { // write your code here for(Integer num : set){ if(num > 10){ set.remove(num); } } return set; } Does any one is having idea about this ? Can you help me to resolve this issue.
RomanLevel 41
29 October 2018, 06:35
You must use an iterator to remove items.
Deepak JoshiLevel 17 , Nainital
1 May, 15:25
use Irerator to remove items otherwise it will raise ConcurrentModificationException