Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Iterator<Integer> it=panel1(1,5);
- for(;it.hasNext();)
- System.out.println(it.next()); // mostra 1 2 3 4 5
- import java.util.List;
- import java.util.AbstractList;
- import java.util.Iterator;
- public class Panel{
- public Iterator<Integer> panel1(int begin, int end){
- it = new IntRangeIterator(begin, end);
- return it;
- }
- public static void main(String[] args) {
- Iterator<Integer> it=panel1(1,5);
- for(;it.hasNext();)
- System.out.println(it.next()); // affiche 1 2 3 4 5
- }
- }
- class IntRangeIterator implements Iterator<Integer> {
- private int nextValue;
- private final int max;
- public IntRangeIterator(int min, int max) {
- if (min > max) {
- throw new IllegalArgumentException("min must be <= max");
- }
- this.nextValue = min;
- this.max = max;
- }
- public boolean hasNext() {
- return nextValue <= max;
- }
- public Integer next() {
- if (!hasNext()) {
- throw new NoSuchElementException();
- }
- return Integer.valueOf(nextValue++);
- }
- public void remove() {
- throw new UnsupportedOperationException();
- }
- }
- Panel.java:9: error: cannot find symbol
- it = new IntRangeIterator(begin, end);
- ^
- symbol: variable it
- location: class Panel
- Panel.java:10: error: cannot find symbol
- return it;
- ^
- symbol: variable it
- location: class Panel
- Panel.java:15: error: non-static method panel1(int,int) cannot be referenced from a static context
- Iterator<Integer> it=panel1(1,5);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement