В лоб можно сделать
import java.util.Arrays;
import java.util.stream.IntStream;
public class Main {
public static void main(String[] args) {
int size = 6;
int[][] matrix = fillMatrix(size);
printMatrix(matrix);
}
public static int[][] fillMatrix(int size) {
int[][] matrix = new int[size][size];
Arrays.setAll(matrix, i -> {
int[] row = new int[size];
Arrays.setAll(row, j -> isCornerOrAdjacent(i, j, size) ? 1 : 0);
return row;
});
return matrix;
}
private static boolean isCornerOrAdjacent(int i, int j, int size) {
return ((i % (size - 1) == 0) && (j = size - 2)) ||
((j % (size - 1) == 0) && (i = size - 2)) ||
((i == 1 || i == size - 2) && (j == 0 || j == size - 1));
}
public static void printMatrix(int[][] matrix) {
IntStream.range(0, matrix.length).forEach(i -> {
IntStream.range(0, matrix.length).forEach(j -> System.out.print(matrix[j] + " "));
System.out.println();
});
}
}
1 1 0 0 1 1
1 0 0 0 0 1
0 0 0 0 0 0
0 0 0 0 0 0
1 0 0 0 0 1
1 1 0 0 1 1