package ru.matevosyan;

/**
 * EvenNumber class.
 * Created on 03.05.2017.
 * @author Matevosyan Vardan
 * @version 1.0
 */

public class NaturalNumber implements NaturalNumberIterator {

    private int index = 0;
    private int j = 0;
    int value = 0;
    private final int[] array;

    /**
     * EvenNumber constructor.
     * @param array an array.
     */

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

    /**
     * Override the next() method to iterate each element from an array.
     * @return even numbers from an array.
     */

    @Override
    public int next() {

        for (int i = index++; i < array.length && index <= array.length; i++) {
//            int num = array[i];
            if ((array[i] > 1) && !(array[i] % 2 == 0) || (array[i] == 2)) {
                value = i;
                break;
            } else {
                index++;
            }
        }
        return array[value];
    }

    /**
     * Override hasNext() method to check if eny of elements are in array to read, looking to next() pointer.
     * @return true if there are any elements to read, else return false.
     */

    @Override
    public boolean hasNext() {
        return array.length > index;
    }
}

@@ -212,50 +212,8 @@
  0;%0A
-    private int j = 0;%0A    int value = 0;%0A
     
@@ -565,17 +565,21 @@
 ext() %7B%0A
-%0A
+//%0A//
         
@@ -650,16 +650,18 @@
  i++) %7B%0A
+//
 //      
@@ -686,16 +686,18 @@
 ray%5Bi%5D;%0A
+//
         
@@ -761,24 +761,26 @@
 i%5D == 2)) %7B%0A
+//
             
@@ -794,16 +794,18 @@
 ue = i;%0A
+//
         
@@ -819,16 +819,18 @@
  break;%0A
+//
         
@@ -842,16 +842,18 @@
  else %7B%0A
+//
         
@@ -869,16 +869,18 @@
 ndex++;%0A
+//
         
@@ -877,32 +877,34 @@
 //            %7D%0A
+//
         %7D%0A      
@@ -897,24 +897,25 @@
       %7D%0A
+%0A
         
 return a
@@ -910,28 +910,195 @@
     
-return array%5Bvalue%5D;
+int result = 0;%0A%0A            if (isSimpleOrNot() && this.array.length %3E this.index) %7B%0A                result = this.array%5Bthis.index%5D;%0Athis.index++;%0A            %7D%0A%0A        return result;%0A
 %0A   
@@ -1362,16 +1362,21 @@
  return 
+this.
 array.le
@@ -1382,21 +1382,586 @@
 ength %3E 
-index
+this.index && (isSimpleOrNot()%7C%7C this.array.length %3E this.index);%0A    %7D%0A%0A    private boolean isSimpleOrNot() %7B%0A        boolean isSimple = true;%0A%0A        if (this.array%5Bthis.index%5D == 1) %7B%0A            this.index++;%0A            isSimple = false;%0A%0A        %7D%0A%0A        for (int i = 2; i %3C= Math.sqrt(this.array%5Bthis.index%5D); i++) %7B%0A%0A%0A            if (this.array%5Bthis.index%5D %25 i == 0) %7B%0A//                this.index++;%0A                isSimple = false;%0A                break;%0A            %7D else  %7B%0A                this.index++;%0A            %7D%0A%0A        %7D%0A%0A        return isSimple
 ;%0A    %7D%0A

add to fix