task1 Matrix Program

program for finding entered triangle is a Upper triangular Matrix/Lower triangular  Matrix/Diagonal Matrix/ Non-triangular Marix

import java.util.Scanner;
public class Matrixprogram {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

int i,j,c1=0,k1=0,c2=0,k2=0,n = 0,d=0,d1=0;
Scanner in = new Scanner(System.in);
System.out.println(“enter the n value”);
n=in.nextInt();
int a[][]=new int[n][n];

for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=in.nextInt();
}

}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
System.out.print(a[i][j]+” “);
}
System.out.println();

}

System.out.println(“sub martix”);

for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{

System.out.print(a[i][j]+” “);
if(a[i][j]==0)
{
c1++;
}
k1++;

}

}

System.out.println(“\ncheck rev sub martix”);
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{

System.out.print(a[j][i]+” “);
if(a[j][i]==0)
{
c2++;
}
k2++;
}

}
for(i=0;i<n;i++)
{
if(a[i][i]==0)
{
d++;
}

}
if((c1==c2)&&(d!=n))
{
System.out.println(“D”);
}
else if((c1==c2)&&(d==n))
{
System.out.println(“N”);
}
else if(c2==k2)

{
System.out.println(“U”);
}
else if(c1==k1)
{
System.out.println(“L”);
}

}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s