Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static void diagSlice(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;
            slice[i] = matrix[row + i][column + columnIdx];
        }
        for (int i = sliceSize; i < slice.length; i++) {
            slice[i] = 0;
        }
    }
}