package ru.matevosyan;

import java.util.Objects;

/**
 * TwoDementionIterator class.
 * Created on 28.04.2017.
 * @author Matevosyan Vardan
 * @version 1.0
 */

public class DimensionalIterator implements ArrayIterator {

    private int indexX = 0;
    private int indexY = 0;
    private final int[][] array;

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

    @Override
    public int next() {
        return array[indexX++][indexY++];
    }


    @Override
    public boolean hasNext() {
        return array.length > indexX && array.length > indexY;
    }
}

@@ -21,35 +21,8 @@
 n;%0A%0A
-import java.util.Objects;%0A%0A
 /**%0A
@@ -412,134 +412,1250 @@
     
-return array%5BindexX++%5D%5BindexY++%5D;%0A    %7D%0A%0A%0A    @Override%0A    public boolean hasNext() %7B%0A        return array.length %3E indexX
+int value = 0;%0A        if (array.length %25 2 == 0 && array%5B0%5D.length %25 2 == 0) %7B%0A            if (indexY %3C array.length) %7B%0A                value = this.array%5BindexX%5D%5BindexY++%5D;%0A            %7D else if (indexX %3C array.length) %7B%0A                indexY = 0;%0A                indexX++;%0A                value = this.array%5BindexX%5D%5BindexY++%5D;%0A            %7D%0A        %7D else %7B%0A            if (indexY %3C array%5B0%5D.length) %7B%0A                value = this.array%5BindexX%5D%5BindexY++%5D;%0A            %7D else if (indexX %3C array.length)%7B%0A                indexY = 0;%0A                indexX++;%0A                value = this.array%5BindexX%5D%5BindexY++%5D;%0A            %7D%0A        %7D%0A        return  value;%0A    %7D%0A%0A%0A    @Override%0A    public boolean hasNext() %7B%0A        boolean has = false;%0A        if (array.length %25 2 == 0 && array%5B0%5D.length %25 2 == 0) %7B%0A%0A            if (indexY %3E= array.length && indexX %3E= array.length - 1) %7B%0A                has = false;%0A            %7D else %7B%0A                has = true;%0A            %7D%0A%0A        %7D else if (array.length %25 2 != 0 &&  array.length %3E array%5B0%5D.length) %7B%0A%0A            if (indexX + indexY %3C= array.length) %7B%0A                has = true;%0A            %7D else %7B%0A                has = false;%0A            %7D%0A        %7D else if (array.length %25 2 == 0
  &&
+ 
  arr
@@ -1668,16 +1668,227 @@
 gth 
-%3E indexY
+%3C array%5B0%5D.length) %7B%0A                if (indexX + indexY %3C= array%5B0%5D.length) %7B%0A                    has = true;%0A                %7D else %7B%0A                    has = false;%0A                %7D%0A            %7D%0A        return has
 ;%0A  

change logic in DimensionalIterator.java