matrix.java

来自「数独的一种实现」· Java 代码 · 共 51 行

JAVA
51
字号
// Decompiled by DJ v3.9.9.91 Copyright 2005 Atanas Neshkov  Date: 2/13/2008 10:16:10 PM
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   Matrix.java


public class Matrix
{

    public Matrix(int i, int j)
    {
        matrix = new int[i][j];
    }

    public void validateParameters(int i, int j)
    {
        if(i >= getNumRows())
            throw new IndexOutOfBoundsException((new StringBuilder()).append("This matrix has only ").append(getNumRows()).append(" rows ").append(" you requested ").append(i).append("!").toString());
        if(j >= getNumColumns())
            throw new IndexOutOfBoundsException((new StringBuilder()).append("This matrix has only ").append(getNumColumns()).append(" columns you requested ").append(j).append("!").toString());
        else
            return;
    }

    public int get(int i, int j)
    {
        validateParameters(i, j);
        return matrix[i][j];
    }

    public void set(int i, int j, int k)
    {
        validateParameters(i, j);
        matrix[i][j] = k;
    }

    public int getNumRows()
    {
        return matrix.length;
    }

    public int getNumColumns()
    {
        if(getNumRows() == 0)
            return 0;
        else
            return matrix[0].length;
    }

    protected int matrix[][];
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?