Page 524 - Cs_withBlue_J_C11_Flipbook
P. 524
Program 14 Define a class transposeSymmetric and check whether the matrix is symmetric or not by
finding its transpose.
Data Members
int n : to store the size of the array
int a[][] : to store the array
Member Methods
void transymcheck() : to find the transpose of the matrix and check for
symmetricity
Write the main method to call the methods and run the program.
1 import java.util.*;
2 class transposeSymmetric
3 {
4 //data members
5 int n;
6 int a[][];
7
8 // member methods
9 void transymcheck()
10 {
11 Scanner sc=new Scanner(System.in);
12 System.out.println("enter the size of the matrix");
13 n=sc.nextInt();
14 a=new int[n][n];//declaration of the array
15 int b[][]=new int[n][n];
16 System.out.println("enter the matrix elements");
17 for(int i=0;i<n;i++)
18 {
19 for(int j=0;j<n;j++)
20 {
21 a[i][j]=sc.nextInt();
22 b[j][i]=a[i][j];
23 }
24 }
25 int flag=0;
26 //checking for symmetricity
27 for(int i=0;i<n;i++)
522522 Touchpad Computer Science-XI

