Monday, March 16, 2020

BlueJ Program on 2 D Symmetric Array And Diagonal Values


For Details of The Program: CLICK HERE


import java.io.*;
class Str2
{
int left=0,right=0,m,i,j, arr[][];
boolean bool=false;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void takeValues() throws Exception
{
System.out.println("Enter the value of 'm';");
m=Integer.parseInt(br.readLine());
if(m >=10)
{
System.out.println("Matrix size is out of range");
return;
}
arr=new int[m][m];
for(i=0;i < m; i++)
{
for(j=0;j < n;j++)
{
System.out.println("value:");
arr[i][j]=Integer.parseInt(br.readLine());
}
}
System.out.println("Original Matrix\n");
for(i=0;i < m : i++)
{
for(j=0;j < n : j++)
{
System.out.print(" "+arr[i][j]);
}
System.out.println();
}
for(i=0;i < m ; i++)
{
for(j=0;j < n; j++)
{
if(arr[i][j]!=arr[j][i])
{

bool=true;
break;
}
}
if(bool==true)
break;
}
if(bool)

System.out.println("The given matrix is not Symmetric"); 
else

System.out.println("The given matrix is Symmetric"); 
for(i=0;i < m ; i++)
{
for(j=0;j < n; j++)
{ 
if(i==j)
left=left+arr[i][j];
if(i+j==m-1)
right=right+arr[i][j];
}
}

System.out.println("Sum of the left diagonal="+left); System.out.println("Sum of the right diagonal="+right); }

public static void main(String args[])throws Exception
{
Str2 ob=new Str2();
ob.takeValues();
}

}

2014 Computer Practical Paper: CLICK HERE

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner