-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathSymmetric.java
More file actions
66 lines (65 loc) · 1.33 KB
/
Symmetric.java
File metadata and controls
66 lines (65 loc) · 1.33 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import java.util.Scanner;
public class Symmetric
{
public static void main(String args[])
{
int rows,cols,i,j,flag=0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the no. of rows of the matrix: ");
rows = sc.nextInt();
System.out.println("Enter the no. of columns of the matrix: ");
cols = sc.nextInt();
if(rows != cols)
{
System.out.println("The given matrix is not a square matrix, so it can't be symmetric.");
}
else
{
int matrix[][] = new int[rows][cols];
System.out.println("Enter the elements :");
for (i = 0; i < rows; i++)
{
for (j = 0; j < cols; j++)
{
matrix[i][j] = sc.nextInt();
}
}
System.out.println("The matrix :");
for (i = 0; i < rows; i++)
{
for (j = 0; j < cols; j++)
{
System.out.print(matrix[i][j]+"\t");
}
System.out.println();
}
System.out.println("The transpose of the matrix :");
for (i = 0; i < rows; i++)
{
for (j = 0; j < cols; j++)
{
System.out.print(matrix[j][i]+"\t");
}
System.out.println();
}
for (i = 0; i < rows; i++)
{
for (j = 0; j < cols; j++)
{
if(matrix[i][j] != matrix[j][i])
{
flag = 1;
}
}
}
if(flag==0)
{
System.out.println("Result: The given matrix is symmetric.");
}
else
{
System.out.println("Result: The given matrix is not symmetric.");
}
}
}
}