import java.io.*;
class outter
{
int a[][]=new int[4][4];
int n,i,j;
public void print()
{
try
{
DataInputStream cin=new DataInputStream(System.in);
System.out.println("Enter the matrix size");
n=Integer.parseInt(cin.readLine());
System.out.println("Enter the matrix elements");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=Integer.parseInt(cin.readLine());
}
}
}
catch(Exception e)
{
System.out.println("wrong data");
}
inner i=new inner();
i.cal();
}
class inner
{
public void cal()
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i==j)
{
a[i][j]=1;
System.out.print(""+a[i][j]);
}
else
{
a[i][j]=0;
System.out.print(""+a[i][j]);
}
System.out.print(" ");
}
System.out.println();
}
}
}
}
class innerclass_identity_matrix
{
public static void main(String args[])
{
outter o=new outter();
o.print();
}
}
class outter
{
int a[][]=new int[4][4];
int n,i,j;
public void print()
{
try
{
DataInputStream cin=new DataInputStream(System.in);
System.out.println("Enter the matrix size");
n=Integer.parseInt(cin.readLine());
System.out.println("Enter the matrix elements");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=Integer.parseInt(cin.readLine());
}
}
}
catch(Exception e)
{
System.out.println("wrong data");
}
inner i=new inner();
i.cal();
}
class inner
{
public void cal()
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i==j)
{
a[i][j]=1;
System.out.print(""+a[i][j]);
}
else
{
a[i][j]=0;
System.out.print(""+a[i][j]);
}
System.out.print(" ");
}
System.out.println();
}
}
}
}
class innerclass_identity_matrix
{
public static void main(String args[])
{
outter o=new outter();
o.print();
}
}
No comments:
Post a Comment