forked from Hasaber8/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiagonalmatrix.java
54 lines (50 loc) · 1.18 KB
/
Diagonalmatrix.java
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.io.*;
class Diagonalmatrix
{
public static void main(String[]args)throws IOException
{
BufferedReader venki=new BufferedReader (new InputStreamReader(System.in));
int a[][]=new int [10][10];
int i,j,row,column,sum=0;
System.out.println("\nEnter the Order of Matrix:");
System.out.println("\nEnter the Rows:");
row=Integer.parseInt(venki.readLine());
System.out.println("\nEnter the Columns:");
column=Integer.parseInt(venki.readLine());
System.out.println("\nEnter the Values of Rows And Columns Respectively!");
for(i=0;i<row;i++)
for(j=0;j<column;j++)
{
a[i][j]=Integer.parseInt(venki.readLine());
}
System.out.println("\nEntered Matrix is:");
for(i=0;i<row;i++)
{
for(j=0;j<column;j++)
{
System.out.print("\t"+a[i][j]);
}
System.out.println("\n");
}
for(i=0;i<row;i++)
for(j=0;j<column;j++)
{
if(i==j)
{
sum=sum+a[i][j];
}
}
System.out.println("\nThe Sum of 1st Diagonal is : "+sum);
sum=0;
i=row;
for(j=0;j<column;j++)
{
while(i==0)
{
sum+=a[j][i];
i--;
}
}
System.out.println("\nThe Sum of Second Diagonal:"+sum);
}
}