how can I fill two-dimensional array of given "size" to get this output:
N=1
000
010
000
N=2
0000
0110
0110
0000
N=3
00000
01110
01210
01110
00000
public static void main (String[] args) throws java.lang.Exception
{
int x, y;
int N = 3;
int counter = 0;
x = y = N + 2;
int[][] array = new int[x][y];
for( int i = 0; i<x; i++){
for( int j = 0; j < y; j++){
if( i == 0 || i == x-1 || j == 0 || j == y-1){
array[i][j] = 0;
} else {
array[i][j] = 1;
}
System.out.print(array[i][j]);
}
System.out.println();
}
}
This code gives me just 1s surrounded by 0, but I cannot figure out how to increase value to the middle of array. If N is an odd number I can use modulo, but i don't know how to do this with even numbers.