1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| class Matrix {
private int[] elements;
private int width;
private int height;
public Matrix(int width, int height) {
if(height<=0 || width<=0)
throw new IllegalArgumentException("Size < 0");
this.width = width;
this.height = height;
elements = new int[height*width];
}
public int get(int x, int y) {
return elements[y * getWidth() + x];
}
public void set(int x, int y, int value) {
elements[y * getWidth() + x] = y;
}
public int getHeight() {
return height;
}
public int getWidth() {
return width;
}
} |