Skip to content

Commit 2103d13

Browse files
committed
Matrix programs
1 parent 617e0d8 commit 2103d13

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

InterviewPrograms/src/com/java/matrix/IdentityMatrix.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ public static void main(String[] args) {
4848
{0,0,1}
4949
};*/
5050
int row = 4;
51-
int col = 4;
51+
int column = 4;
5252

53-
//row and col should be same to make square matrix
54-
if(row != col){
53+
//row and column should be same to make square matrix
54+
if(row != column){
5555
System.out.println("Given matrix is NOT a Identity Matrix");
5656
return;
5757
}
@@ -65,7 +65,7 @@ public static void main(String[] args) {
6565

6666
//rest of the elements should be 0
6767
for(int i=0;i<row;i++)
68-
for(int j=0;j<col;j++)
68+
for(int j=0;j<column;j++)
6969
if(i != j && matrix[i][j] != 0){
7070
System.out.println("Given matrix is NOT a Identity Matrix");
7171
return;
@@ -77,40 +77,35 @@ public static void main(String[] args) {
7777
}
7878
}
7979
/*
80-
INPUT
80+
OUTPUT
8181
matrix[][] = {
8282
{1,0,0,0},
8383
{0,1,0,0},
8484
{0,0,1,0},
8585
{0,0,0,1}
8686
};
87-
OUTPUT
8887
Given matrix is a Identity Matrix
8988
90-
INPUT
89+
OUTPUT
9190
matrix[][] = {
9291
{1,0,0},
9392
{0,1,0},
9493
{0,0,1},
9594
};
96-
OUTPUT
9795
Given matrix is a Identity Matrix
9896
99-
INPUT
97+
OUTPUT
10098
matrix[][] = {
10199
{1,1,1},
102100
{0,1,1},
103101
{1,0,1},
104102
};
105-
OUTPUT
106103
Given matrix is NOT a Identity Matrix
107104
108-
INPUT
105+
OUTPUT
109106
matrix[][] = {
110107
{1,0,0},
111108
{0,1,0}
112109
};
113-
OUTPUT
114-
Given matrix is NOT a Identity Matrix
115-
110+
Given matrix is NOT a Identity Matrix
116111
*/

InterviewPrograms/src/com/java/matrix/MatrixAddition.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@ static void display(int matrix[][],int rows,int columns){
7070
5 6 7 8
7171
9 10 11 12
7272
13 14 15 16
73+
7374
Matrix B is ::
7475
5 10 15 20
7576
25 30 35 40
7677
45 50 55 60
7778
65 70 75 80
79+
7880
OUTPUT
7981
Addition of two matrix is ::
8082
6 12 18 24
@@ -86,10 +88,12 @@ static void display(int matrix[][],int rows,int columns){
8688
Matrix A is ::
8789
1 2 3 4
8890
5 6 7 8
91+
8992
Matrix B is ::
9093
5 10 15
9194
20 25 30
9295
35 40 45
96+
9397
OUTPUT
9498
Addition is not possible
9599

InterviewPrograms/src/com/java/matrix/MatrixMultiplication.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ static void display(int matrix[][],int rows,int columns){
8282
}
8383
}
8484
/*
85+
OUTPUT
8586
Matrix A is ::
8687
1 1
8788
2 2

InterviewPrograms/src/com/java/matrix/SparseMatrix.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
/*
44
* Sparse Matrix
55
*
6-
* First count the number of zero elements in
7-
* the matrix.
8-
* Then calculate the size of the
9-
* matrix (row*column).
6+
* First count the number of zero elements in the matrix.
7+
* Then calculate the size of the matrix (row*column).
108
*
119
* For the matrix to be Sparse Matrix,
1210
* count of the zero elements should be greater

0 commit comments

Comments
 (0)