Upload files to "OOP/Java/Lab/Week4"
This commit is contained in:
parent
f7cc8cb99a
commit
48775a2c5e
4 changed files with 168 additions and 0 deletions
41
OOP/Java/Lab/Week4/SymmMatrixCheck.java
Normal file
41
OOP/Java/Lab/Week4/SymmMatrixCheck.java
Normal file
|
@ -0,0 +1,41 @@
|
|||
import java.util.Scanner;
|
||||
|
||||
class SymmMatrixCheck {
|
||||
|
||||
public static void main(String args[]) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
System.out.print("Enter the number of rows in the matrix: ");
|
||||
int m = sc.nextInt();
|
||||
System.out.print("Enter the number of colums in the matrix: ");
|
||||
int n = sc.nextInt();
|
||||
|
||||
int a[][] = new int[m][n];
|
||||
for (int i = 0; i < m; i++) {
|
||||
for (int j = 0; j < n; j++) {
|
||||
System.out.print(
|
||||
"Enter the element at (" + i + "," + j + "): "
|
||||
);
|
||||
a[i][j] = sc.nextInt();
|
||||
}
|
||||
}
|
||||
|
||||
boolean isSymmetric = true;
|
||||
for (int i = 0; i < m; i++) {
|
||||
for (int j = 0; j < n; j++) {
|
||||
if (i != j && a[i][j] != a[j][i]) {
|
||||
isSymmetric = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isSymmetric) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isSymmetric) {
|
||||
System.out.println("The matrix is symmetric.");
|
||||
} else {
|
||||
System.out.println("The matrix is not symmetric.");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue