Hi,
the second and the fourth condition fails, and i have no idea, what is causing this error. Maybe someone smarter than me can help me
to find and resolve my mistake or mistakes.
Best regards
Steffen
package de.codegym.task.task08.task0814;
import java.util.HashSet;
import java.util.Set;
import java.util.Iterator;
import java.lang.Math;
/*
Größer als 10? Du passt nicht gut zu uns
*/
class Debug{
public static boolean debug = false;
}
public class Solution {
public static HashSet<Integer> setErstellen() {
// schreib hier deinen Code
HashSet in = new HashSet<Integer>();
for (int i = 0; i < 20; i++) {
in.add(i);
}
if(Debug.debug){
System.out.println("Set: " + in);
System.out.println("Size: " + in.size());
}
return in;
}
public static HashSet<Integer> alleZahlenGroesserAls10Entfernen(HashSet<Integer> set) {
// schreib hier deinen Code
HashSet<Integer> result = new HashSet<Integer>();
Iterator<Integer> it = set.iterator();
while(it.hasNext()){
Integer x = it.next();
if(Debug.debug){
System.out.println(x);
}
if(x <= 10){
if(Debug.debug){
System.out.println("Added to result: " + x);
}
result.add(x);
}
else{
if(Debug.debug){
System.out.println("Not added to result: " + x);
}
//result.remove(x);
}
}
/*
for(Integer x : set){
if(x <= 10){
if(Debug.debug){
System.out.println("Added to result: " + x);
}
result.add(x);
}
else{
if(Debug.debug){
System.out.println("Not added to result: " + x);
}
}
}
*/
if(Debug.debug){
System.out.println("Result: " + result);
System.out.println("Size: " + result.size());
}
return result;
}
public static void main(String[] args) {
HashSet<Integer> x = setErstellen();
alleZahlenGroesserAls10Entfernen(x);
}
}