Categories

# Class 11 NonBound Program ISC 2020

A class NonBound contains a square matrix which finds the sum of the non-boundary elements of the matrix.

Some of the members of the class are given below:
Class name: NonBound
Data members/instance variables:
arr[][]: array to store integer elements.
n: to store the order of the matrix.
Member functions/methods:
NonBound(int mm): parameterized constructor to initialize the data member n = mm.
void fillArray(): to fill the array elements.
void sumOfNon(): finds and displays the sum of the non-boundary elements in the matrix with an appropriate message.
void display(): displays the array elements in matrix form.

Define the class NonBound giving details of the constructor, void fillArray(), void sumOfNon() and void display(). Define the main() function to create an object and call the functions accordingly to enable the task.

``````import java.io.*;
class NonBound{
int arr[][];
int n;
public NonBound(int mm){
n = mm;
arr = new int[n][n];
}
public void fillArray()throws IOException{
System.out.println("Enter array elements:");
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
}
}
}
public void sumOfNon(){
int sum = 0;
for(int i = 1; i < n - 1; i++){
for(int j = 1; j < n - 1; j++){
sum += arr[i][j];
}
}
System.out.println("Sum of non-boundary elements: " + sum);
}
public void display(){
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
System.out.print(arr[i][j] + "\t");
}
System.out.println();
}
}
public static void main(String args[])throws IOException{