-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiagonal.java
More file actions
46 lines (46 loc) · 1.23 KB
/
Copy pathDiagonal.java
File metadata and controls
46 lines (46 loc) · 1.23 KB
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
import java.util.Scanner;
class Diagonal
{
public static void main(String args[])
{
int m,n,c=0,d=0,b=0;
Scanner sc=new Scanner(System.in);
System.out.println("enter the limits of the matrix");
m=sc.nextInt();
n=sc.nextInt();
int a[][]=new int[m][n];
System.out.println("enter the elements in the matrix");
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
a[i][j]=sc.nextInt();
System.out.println("the matrix is:");
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
System.out.print(a[i][j]);
System.out.println();
}
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
if(i==j)
{
if(a[i][j]==0)
b++;
else if(a[i][j]!=0)
c++;
}
else
{
if(a[i][j]==0)
d++;
}
}
}
if(c==(m-b)&&d==((m*n)-m)&&b!=m)
System.out.print("It is a diagonal matrix");
else
System.out.print("It isn't a diagonal matrix");
}
}