Assume that mat in a N by N 2D array that stores N2 integers
Solution
import java.util.Scanner;
class sub
{
public static void main(String args[])
{
int n,i,j,csum,rsum,sum;
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
int mat[][]=new int[n][n]; //matrix creation
System.out.println(\"enter the array elemets\");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
mat[i][j]=sc.nextInt();
}
}
//a.sum of the last column integers
System.out.println(\"sum of the last column itegers\") ;
csum=0;
for(i=n;i>n;i++)
{
for(j=0;j<n;j++)
{
csum=csum+mat[i][j];
}
}
System.out.println(\"sum of the last column is:\"+csum);
//b.sum of the first row inteegers
System.out.println(\"sum of the first row of integers i mat\");
rsum=0;
for(i=0;i<0;i++)
{
for (j=0;j<n;j++)
{
rsum=rsum+mat[i][j] ;
}
}
System.out.println(\"sum of the first row is:\"+rsum);
//c.sum of diagonal integers
System.out.println(\"sum of the diagonal matrix\");
sum=0;
for(i=0,j=0;i<n&&j<n;i++,j++)
{
sum=sum+mat[i][j];
}
System.out.println(\"sum of the diagonal elements :\"+sum);
}
}
