-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilledMatrixPrinter
More file actions
33 lines (29 loc) · 936 Bytes
/
FilledMatrixPrinter
File metadata and controls
33 lines (29 loc) · 936 Bytes
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
32
33
import java.util.Scanner;
public class FilledMatrixPrinter {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.print("Enter Rows: ");
int rows = s.nextInt();
System.out.print("Enter Cols: ");
int cols = s.nextInt();
System.out.print("Enter Filler");
int filler = s.nextInt();
s.close();
int matrix [][] = new int [rows][cols];
if (rows > 0 && cols >0){
for(int i = 0; i<rows; i++){
for (int k = 0; k< cols; k++){
matrix[i][k] = filler;
System.out.print(matrix[i][k]+ "\t");
}
System.out.println();
}
}
else if (rows<0 || cols<0){
throw new IllegalArgumentException("IllegalArgumentException");
}
else{
System.out.println();
}
}
}