So I have to print out an array which:
- The first cell defines the dimension of the square array. So, I have the
input
Scanner
. - On the first row of the array, every cell has to be the triple of the previous one minus one.
- For every next row, every cell has to have the double of the same column of the previous line, plus the number of the column.
- For example: if the input of the dimensions is 4, like
showArrray(creerArray(4));
, then it should print something like:
4 11 32 95
8 23 66 193
16 47 134 389
32 95 270 781
I already coded the part for the input dimension, but I am stuck at trying to figure out how to code this sequence:
public static void showArray() {
}
public static void createArray() {
int square= 0;
int[][] int2D = new int[square][square];
java.util.Scanner input = new Scanner(System.in);
square= input.nextInt();
System.out.println("Enter the dimension of the array:" + square);
int counter=0;
for(int i=0; i<square; i++) {
for(int j=0; j<square; j++){
int2D[i][j]=counter;
counter++;
}
input.close();
}
****i have to start coding the sequence here
}