package Iterator;

import java.util.Iterator;

/**
 * Created by user8.3 on 24.05.2017.
 */
public class IteratorArray implements Iterator<Integer> {
    private int[] array;
    private int index = 0;

    public IteratorArray(int[] array) {
        this.array = array;
    }

    public boolean hasNext() {
        if (index < array.length) {
            for (int i = 0; i < array.length - index; i++) {
                if (array[index + i] %2 == 0) {
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    public Integer next() {
        if (array[index] % 2 == 0) {
            return array[index++];
        } else {
            while (array[index++] % 2 != 0 && index < array.length) {
            }
            return array[index - 1];
        }
    }

    @Override
    public void remove() {

    }
}
@@ -593,34 +593,37 @@
 ext() %7B%0A        
-if
+while
  (array%5Bindex%5D %25
@@ -625,17 +625,17 @@
 ex%5D %25 2 
-=
+!
 = 0) %7B%0A 
@@ -648,30 +648,15 @@
     
- return array%5B
 index++
-%5D
 ;%0A  
@@ -666,104 +666,9 @@
    %7D
- else %7B
 %0A
-            while (array%5Bindex++%5D %25 2 != 0 && index %3C array.length) %7B%0A            %7D%0A    
     
@@ -693,24 +693,12 @@
 ndex
- - 1%5D;%0A        %7D
+++%5D;
 %0A   

task 151