Java tutorial
//package com.java2s; public class Main { public static void applyDiagSlice(int[][] matrix, int row, int column, boolean forwards, int[] slice) { int sliceSize = Math.min(matrix.length - row, forwards ? matrix[0].length - column : column + 1); for (int i = 0; i < sliceSize; i++) { int columnIdx = forwards ? i : -i; matrix[row + i][column + columnIdx] = slice[i]; } } }