how to generate a sequence from a two dimensional array

36 Views Asked by At

I was told to generate a sequence of numbers in the picture attached

The numbers highlighted in blue

For that I used

int[][] generate2DArray(int numberOfRows, int noOfColumns){
    int[][] dynamic2DArray = new int[12][12];

    int outerRowLimit = dynamic2DArray.length;
    int innerColumnLimit = dynamic2DArray[0].length;

    int outerLoopCounter = 0;
    int innerLoopCounter = 0;

    while(outerLoopCounter < outerRowLimit){
        while(innerLoopCounter < innerColumnLimit){
            int currentElement = (outerLoopCounter + 1) * (innerLoopCounter + 1);
            dynamic2DArray[outerLoopCounter][innerLoopCounter] = currentElement;
            innerLoopCounter++;
        }
        innerLoopCounter = 0;
        outerLoopCounter++;
    }
    return dynamic2DArray;
}

The problem now is that I was told to generate those highlighted in yellow. Can any one help?

I tried int currentElement = (innerLoopCounter + 10)-2;

0

There are 0 best solutions below