mirror of
https://bitbucket.org/Mattrixwv/matrix.git
synced 2025-12-06 23:13:57 -05:00
Added constructor for a filled matrix
This commit is contained in:
@@ -120,6 +120,22 @@ public class IntegerMatrix{
|
|||||||
public IntegerMatrix(IntegerMatrix matrix){
|
public IntegerMatrix(IntegerMatrix matrix){
|
||||||
setGrid(matrix.grid);
|
setGrid(matrix.grid);
|
||||||
}
|
}
|
||||||
|
public IntegerMatrix(int rows, int cols, int fill){
|
||||||
|
if(rows <= 0){
|
||||||
|
throw new InvalidGeometryException("A filled matrix must have at least 1 row");
|
||||||
|
}
|
||||||
|
else if(cols <= 0){
|
||||||
|
throw new InvalidGeometryException("A filled matrix must have at least 1 column");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
grid = new int[rows][cols];
|
||||||
|
for(int row = 0;row < rows;++row){
|
||||||
|
for(int col = 0;col < cols;++col){
|
||||||
|
grid[row][col] = fill;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Gets
|
//Gets
|
||||||
public int get(int row, int col){
|
public int get(int row, int col){
|
||||||
|
|||||||
Reference in New Issue
Block a user