-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSymmetric.java
More file actions
74 lines (65 loc) · 2.25 KB
/
Symmetric.java
File metadata and controls
74 lines (65 loc) · 2.25 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
67
68
69
70
71
72
73
74
// Program: Check for Symmetric and Skew-Symmetric Matrices
// Topic: 2D Arrays and Matrix Properties
// Description: Reads a 3x3 matrix from user input and checks whether it is symmetric or skew-symmetric.
// Uses separate methods to compare elements across the main diagonal and displays the result based on user choice.
package Array2D;
import java.util.*;
/**
*
* @author Samim
*/
public class Symmetric {
public boolean SymmetricCheck(int ar[][]){
for(int i=0;i<ar.length;i++){
for(int j=0;j<ar.length;j++){
if(ar[i][j]!=ar[j][i]){
return false;
}
}
}
return true;
}
public boolean SkewSymmetricCheck(int ar[][]){
for(int i=0;i<ar.length;i++){
for(int j=0;j<ar.length;j++){
if(ar[i][j]!=-(ar[j][i])){
return false;
}
}
}
return true;
}
public static void main(String []args){
Scanner sc=new Scanner(System.in);
int ch;
int arr[][]=new int [3][3];
System.out.println("Enter The Elements :");
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
arr[i][j]=sc.nextInt();
}
}
System.out.println("Enter Choice :");
System.out.println("1.Symmetric");
System.out.println("2.Skew Symmetric");
ch=sc.nextInt();
Symmetric obj=new Symmetric();
switch (ch) {
case 1 : {
boolean flag=obj.SymmetricCheck(arr);
if(flag==true)
System.out.println("Symmetric Matrix !");
else
System.out.println("Non Symmertric Matrix !");
}
case 2 : {
boolean flag2=obj.SkewSymmetricCheck(arr);
if(flag2==true)
System.out.println("Skew-Symmetric Matrix !");
else
System.out.println("Non Skew-Symmertric Matrix !");
}
default : throw new AssertionError();
}
}
}