Page 594 - ComputerScience_Class_11
P. 594
Program 15 Define a class transposeSymmetric and check whether the matrix is symmetric or not.
Data Members
int n : to store the size of the array
int a[][] : to store the array
Member Methods
void transymcheck() : to check for symmetry.
Write the main method to call the methods and run the program.
1 import java.util.Scanner;
2 public class transposeSymmetric
3 {
4 int n;
5 int a[][];
6 public transposeSymmetric(int size)
7 {
8 this.n = size;
9 this.a = new int[n][n];
10 }
11 void inputMatrix(Scanner sc)
12 {
13 System.out.println("Enter the elements for a " + n + "x" + n + " matrix:");
14 for (int i = 0; i < n; i++) {
15 for (int j = 0; j < n; j++) {
16 a[i][j] = sc.nextInt();
17 }
18 }
19 }
20 void transymcheck() {
21 boolean isSymmetric = true;
22 for (int i = 0; i < n; i++) {
23 for (int j = 0; j < i; j++) {
24 if (a[i][j] != a[j][i]) {
25 isSymmetric = false;
592 Touchpad Computer Science (Ver. 3.0)-XI

