Advertisement
kkricardokaka95

OOPM A1 3

Sep 8th, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class symmetric
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.         int i,j,n,m;
  8.         System.out.println("Enter the number of rows and columns of the Matrix");
  9.         Scanner t=new Scanner(System.in);
  10.         n=t.nextInt();
  11.         m=t.nextInt();
  12.         int a[][]= new int[n][m];
  13.         System.out.println("Enter the elements of the matrix");
  14.         for(i=0;i<n;++i)
  15.         {
  16.             for(j=0;j<m;++j)
  17.                 a[i][j]=t.nextInt();
  18.         }
  19.         System.out.println("Entered matrix");
  20.         for(i=0;i<n;++i)
  21.         {
  22.             for(j=0;j<m;++j)
  23.                 System.out.print(a[i][j] + "\t");
  24.             System.out.println();
  25.         }
  26.    
  27.         int flag=1;
  28.         for(i=0;i<n;++i)
  29.         {
  30.             for(j=0;j<m;++j)
  31.             {
  32.                 if(a[i][j]==a[j][i])
  33.                     continue;
  34.                 else
  35.                 {
  36.                     flag = 0;
  37.                     break;
  38.                 }
  39.             }
  40.         }
  41.         if(flag==0)
  42.         System.out.println("Matrix is not symmetric");
  43.         else
  44.         System.out.println("Matrix is symmetric");
  45.     }  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement