// adapted from https://docs.oracle.com/javase/tutorial/java/javaOO/innerclasses.html

// we want to create an array, and have a way to print out just the even-numbered 
// elements [0], [2], [4].. To do, we create an inner class where we define the classic
// iteration functions hasNext() and next(), and use that class (its two methods) to 
// custom-iterate (step through the even-numbered elements)

public class NumArray {
  
  // Create an array
  int size=25;
  private int[] arrayOfInts = new int[size];
  
  public NumArray() {
    // fill the array with ascending integer values
    for (int i = 0; i < size; i++) {
      arrayOfInts[i] = i;
    }
  }// constructor
  
  public void printEven() {
    
    // create an obj of our inner class type!
    EvenIterator iterator = new EvenIterator();
    while (iterator.hasNext()) {
      System.out.print(iterator.next() + " ");
    }
    System.out.println();
  }// printEven()
  
  
  /////////////////////////////////////////////////////////////////////////////
  // INNER class  
  // note that inside, we can access members+methods (size, arrayOfInts)
  // of our enclosing (NumArray) class 
  private class EvenIterator {
    
    // Start stepping through the array from the beginning
    private int nextIndex = 0;
    
    public boolean hasNext() {
      
      // Check if the current element is the last in the array
      return (nextIndex <= (size - 1));
    } // hasNext()       
    
    public Integer next() {
      
      // Record a value of an even index of the array
      Integer retValue = Integer.valueOf(arrayOfInts[nextIndex]);
      
      // get ready to return the next even element
      nextIndex += 2;
      
      return retValue;
    }// next()
  }// class EvenIterator
  /////////////////////////////////////////////////////////////////////////////
  
  public static void main(String s[]) {
    
    NumArray nA = new NumArray();
    nA.printEven();
  }// main()
}// class NumArray