I have a class BoundedSkipper
that implements Iterable<Integer>
, which looks like public Iterator<Integer> iterator() {}
BoundedSkipper
is supposed to take in two integers (int k, int n) where int k is supposed to be the number of integers greater than 0 that should be printed if the integer is NOT divisible or contains 3 in it.
For example:
for (int v: new BoundedSkipper(3, 11)) {
System.out.println(v);
}
the output would be 1, 2, 4, 5, 7, 8, 10, 11, 14, 16, 17
where k
= 3 and n
= 11,
since the total number of integers is n
which is 11, and all the integers excluded, which are 3, 6, 9, 12, 13, 15 are all either divisible or contains k
which is 3.
Here is my code so far:
public class BoundedSkipper implements Iterable<Integer> {
int k;
int n;
public BoundedSkipper(int k, int n) {
this.k = k;
this.n = n;
}
int count = 0;
@Override
public Iterator<Integer> iterator() {
while (count < k) {
}
}
}
The reason why I left this blank is I have absolutely no clue on how to return k
numbers that satisfy the condition since there is no specific parameter in this. Any help WITH CODE EXPLANATION would be extremely useful. Thank you.