/*read 3x3 matrix elements and print diagonal sum
Ex:-
1 2 3
4 5 6
7 8 9
d1=1+5+9 = 15
d2=3+5+7 = 15
*/
import java.io.*;
import java.util.*;
class Matrix
{
private int mat[][];
int c,r;
public void populate(int r , int c)
{
this.c=c;
this.r=r;
mat=new int[r][c];
Scanner in=new Scanner(System.in);
System.out.println("Enter "+r+" X " +c+" Matrix elements?");
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
mat[i][j]=in.nextInt();
}
}
}
public void disMatrix()
{
System.out.println(" Matrix elements are..");
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
System.out.print(mat[i][j]+" ");
}
System.out.print("\n");
}
}
}
class DiagTest
{
public static void main(String a[])
{
Matrix m=new Matrix();
m.populate(3,3);
m.disMatrix();
}
}
/* add diagonal1() and diagonal2() methods to display the diagonal
sum */
Ex:-
1 2 3
4 5 6
7 8 9
d1=1+5+9 = 15
d2=3+5+7 = 15
*/
import java.io.*;
import java.util.*;
class Matrix
{
private int mat[][];
int c,r;
public void populate(int r , int c)
{
this.c=c;
this.r=r;
mat=new int[r][c];
Scanner in=new Scanner(System.in);
System.out.println("Enter "+r+" X " +c+" Matrix elements?");
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
mat[i][j]=in.nextInt();
}
}
}
public void disMatrix()
{
System.out.println(" Matrix elements are..");
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
System.out.print(mat[i][j]+" ");
}
System.out.print("\n");
}
}
}
class DiagTest
{
public static void main(String a[])
{
Matrix m=new Matrix();
m.populate(3,3);
m.disMatrix();
}
}
/* add diagonal1() and diagonal2() methods to display the diagonal
sum */