You are on page 1of 2

import java.util.

*;
public class NonBound
{
int arr[][],m1,n1,i,j,s=0;
Scanner sc=new Scanner(System.in);
NonBound(int n)
{
m1=n;
n1=n;
mat=new int[m1][n1];
}
void fillarray()
{
System.out.println("Enter the array elements");
for(i=0;i<m1;i++)
{
for(j=0;j<n1;j++)
{
mat[i][j]=sc.nextInt();
}
}
}

void sum_of_non()
{
for(i=0;i<m1;i++)
{
for(j=0;j<n1;j++)
{
//check for non-border elements
if( i > 0 && i < m1-1 && j > 0 && j < m1-1 ){
//if(i==0||j==0||i==m1-1||j==n1-1)
{
System.out.print(arr[i][j]+" ");
s=s+arr[i][j];
}
else
{
System.out.println(" ");
}
}
}
}

void display()
{
System.out.println(" ");
for(i=0;i<m1;i++)
{
for(j=0;j<n1;j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println(" ");
}
System.out.println("The sum is "+s);
}

public static void main()


{
int i,j,size;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the size of the array");
size=sc.nextInt();
NonBound ob=new NonBound(size);
ob.fillarray();
ob.sum_of_non();
ob.display();
}
}

You might also like