Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. Iterator<Integer> it=panel1(1,5);
  2. for(;it.hasNext();)
  3. System.out.println(it.next()); // mostra 1 2 3 4 5
  4.  
  5. import java.util.List;
  6. import java.util.AbstractList;
  7. import java.util.Iterator;
  8.  
  9. public class Panel{
  10.  
  11. public Iterator<Integer> panel1(int begin, int end){
  12. it = new IntRangeIterator(begin, end);
  13. return it;
  14. }
  15.  
  16. public static void main(String[] args) {
  17.  
  18. Iterator<Integer> it=panel1(1,5);
  19. for(;it.hasNext();)
  20. System.out.println(it.next()); // affiche 1 2 3 4 5
  21. }
  22. }
  23.  
  24. class IntRangeIterator implements Iterator<Integer> {
  25. private int nextValue;
  26. private final int max;
  27. public IntRangeIterator(int min, int max) {
  28.  
  29. if (min > max) {
  30. throw new IllegalArgumentException("min must be <= max");
  31. }
  32. this.nextValue = min;
  33. this.max = max;
  34. }
  35.  
  36. public boolean hasNext() {
  37. return nextValue <= max;
  38. }
  39.  
  40. public Integer next() {
  41. if (!hasNext()) {
  42. throw new NoSuchElementException();
  43. }
  44. return Integer.valueOf(nextValue++);
  45. }
  46.  
  47. public void remove() {
  48. throw new UnsupportedOperationException();
  49. }
  50. }
  51.  
  52. Panel.java:9: error: cannot find symbol
  53. it = new IntRangeIterator(begin, end);
  54. ^
  55. symbol: variable it
  56. location: class Panel
  57. Panel.java:10: error: cannot find symbol
  58. return it;
  59. ^
  60. symbol: variable it
  61. location: class Panel
  62. Panel.java:15: error: non-static method panel1(int,int) cannot be referenced from a static context
  63. Iterator<Integer> it=panel1(1,5);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement